DaemonApplication
Extends CliApplicationClass to turn CliApplication applications into daemons. It requires CLI and PCNTL support built into PHP.
| link | |
|---|---|
| since |
1.7.0 |
| package |
Joomla CMS |
Methods
__construct
Class constructor.
__construct(\Joomla\CMS\Input\Cli input = null, \Joomla\Registry\Registry config = null, \Joomla\Event\DispatcherInterface dispatcher = null) :
| since |
1.7.0 |
|---|
Arguments
- input
Cli|nullAn optional argument to provide dependency injection for the application's input object. If the argument is a JInputCli object that object will become the application's input object, otherwise a default input object is created.- config
Registry|nullAn optional argument to provide dependency injection for the application's config object. If the argument is a Registry object that object will become the application's config object, otherwise a default config object is created.- dispatcher
DispatcherInterface|nullAn optional argument to provide dependency injection for the application's event dispatcher. If the argument is a DispatcherInterface object that object will become the application's event dispatcher, if it is null then the default event dispatcher will be created based on the application's loadDispatcher() method.
Response
mixed
changeIdentity
Method to change the identity of the daemon process and resources.
changeIdentity() :
| since |
1.7.0 |
|---|---|
| see | posix_setuid() |
Response
boolTrue if identity successfully changed
daemonize
Method to put the application into the background.
daemonize() :
| since |
1.7.0 |
|---|---|
| throws |
|
Response
bool
detach
This is truly where the magic happens. This is where we fork the process and kill the parent process, which is essentially what turns the application into a daemon.
detach() :
| since |
3.0.0 |
|---|---|
| throws |
|
Response
void
execute
Execute the daemon.
execute() :
| since |
1.7.0 |
|---|
Response
void
fork
Method to fork the process.
fork() :
| since |
1.7.0 |
|---|---|
| throws |
|
Response
intThe child process id to the parent process, zero to the child process.
gc
Method to perform basic garbage collection and memory management in the sense of clearing the stat cache. We will probably call this method pretty regularly in our main loop.
gc() :
| since |
1.7.0 |
|---|
Response
void
isActive
Check to see if the daemon is active. This does not assume that $this daemon is active, but only if an instance of the application is active as a daemon.
isActive() :
| since |
1.7.0 |
|---|
Response
boolTrue if daemon is active.
loadConfiguration
Load an object or array into the application configuration object.
loadConfiguration( data) : \Joomla\CMS\Application\DaemonApplication
| since |
1.7.0 |
|---|
Arguments
- data
mixedEither an array or object to be loaded into the configuration object.
Response
DaemonApplicationInstance of $this to allow chaining.
pcntlChildExitStatus
Method to return the exit code of a terminated child process.
pcntlChildExitStatus( status) :
| see | pcntl_wexitstatus() |
|---|---|
| since |
1.7.3 |
Arguments
- status
intThe status parameter is the status parameter supplied to a successful call to pcntl_waitpid().
Response
intThe child process exit code.
pcntlFork
Method to return the exit code of a terminated child process.
pcntlFork() :
| see | pcntl_fork() |
|---|---|
| since |
1.7.3 |
Response
intOn success, the PID of the child process is returned in the parent's thread
of execution, and a 0 is returned in the child's thread of execution. On
failure, a -1 will be returned in the parent's context, no child process
will be created, and a PHP error is raised.
pcntlSignal
Method to install a signal handler.
pcntlSignal( signal, Warning: Array to string conversion in /opt/phpdoc/vendor/twig/twig/src/Extension/CoreExtension.php on line 841 |Array handler, restart = true) :
| see | pcntl_signal() |
|---|---|
| since |
1.7.3 |
Arguments
- signal
intThe signal number.- handler
callableThe signal handler which may be the name of a user created function, or method, or either of the two global constants SIG_IGN or SIG_DFL.- restart
boolSpecifies whether system call restarting should be used when this signal arrives.
Response
boolTrue on success.
pcntlWait
Method to wait on or return the status of a forked child.
pcntlWait( &status, options) :
| see | pcntl_wait() |
|---|---|
| since |
1.7.3 |
Arguments
- status
intStatus information.- options
intIf wait3 is available on your system (mostly BSD-style systems), you can provide the optional options parameter.
Response
intThe process ID of the child which exited, -1 on error or zero if WNOHANG
was provided as an option (on wait3-available systems) and no child was available.
postFork
Method to handle post-fork triggering of the onFork event.
postFork() :
| since |
3.0.0 |
|---|
Response
void
restart
Restart daemon process.
restart() :
| since |
1.7.0 |
|---|
Response
void
setupSignalHandlers
Method to attach the DaemonApplication signal handler to the known signals. Applications can override these handlers by using the pcntl_signal() function and attaching a different callback method.
setupSignalHandlers() :
| since |
1.7.0 |
|---|---|
| see | pcntl_signal() |
Response
bool
shutdown
Method to shut down the daemon and optionally restart it.
shutdown( restart = false) :
| since |
1.7.0 |
|---|
Arguments
- restart
boolTrue to restart the daemon on exit.
Response
void
signal
Method to handle POSIX signals.
signal( signal) :
| since |
1.7.0 |
|---|---|
| see | pcntl_signal() |
| throws |
|
Arguments
- signal
intThe received POSIX signal.
Response
void
stop
Stop daemon process.
stop() :
| since |
1.7.0 |
|---|
Response
void
writeProcessIdFile
Method to write the process id file out to disk.
writeProcessIdFile() :
| since |
1.7.0 |
|---|
Response
bool
Properties
signals
The available POSIX signals to be caught by default.
| link | |
|---|---|
| since |
1.7.0 |
Type(s)
array<string|int, mixed>
exiting
True if the daemon is in the process of exiting.
| since |
1.7.0 |
|---|
Type(s)
bool
parentId
The parent process id.
| since |
3.0.0 |
|---|
Type(s)
int
processId
The process id of the daemon.
| since |
1.7.0 |
|---|
Type(s)
int
running
True if the daemon is currently running.
| since |
1.7.0 |
|---|
Type(s)
bool