streams/Code/Daemon/README.md

44 lines
1.4 KiB
Markdown
Raw Normal View History

2016-06-27 04:58:09 +00:00
Daemon (background) Processes
=============================
This directory provides background tasks which are executed by a
command-line process and detached from normal web processing.
Background tasks are invoked by calling
2022-02-16 04:08:28 +00:00
Code\Daemon\Run::Summon([ $cmd, $arg1, $argn... ]);
2016-06-27 04:58:09 +00:00
The Run class loads the desired command file and passes the arguments.
2016-06-27 04:58:09 +00:00
To create a background task 'Foo' use the following template.
<?php
2022-02-16 04:08:28 +00:00
namespace Code\Daemon;
2016-06-27 04:58:09 +00:00
class Foo {
static public function run($argc,$argv) {
// do something
}
}
The Run class "summons" the command by creating an executable script
2016-06-27 04:58:09 +00:00
from the provided arguments, then it invokes "Release" to execute the script
detached from web processing. This process calls the static::run() function
with any command line arguments using the traditional argc, argv format.
Please note: These are *real* $argc, $argv variables passed from the command
line, and not the parsed argc() and argv() functions/variables which were
obtained from parsing path components of the request URL by web processes.
Background processes do not emit displayable output except through logs. They
should also not make any assumptions about their HTML and web environment
(as they do not have a web environment), particularly with respect to global
variables such as $_SERVER, $_REQUEST, $_GET, $_POST, $_COOKIES, and $_SESSION.