AbstractDaemonApplication
Extends \Joomla\Application\AbstractCliApplication Implements \Psr\Log\LoggerAwareInterfaceClass to turn Cli applications into daemons. It requires CLI and PCNTL support built into PHP.
link | |
---|---|
since |
1.0 |
deprecated |
2.0 Deprecated without replacement |
Methods
__construct
Class constructor.
__construct(\Joomla\Input\Input $input = null, \Joomla\Registry\Registry $config = null)
since |
1.0 |
---|
Arguments
- $input
\Joomla\Input\Input
An optional argument to provide dependency injection for the application's input object. If the argument is an Input object that object will become the application's input object, otherwise a default input object is created.- $config
\Joomla\Registry\Registry
An 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.
changeIdentity
Method to change the identity of the daemon process and resources.
changeIdentity() : boolean
since |
1.0 |
---|---|
see | \Joomla\Application\posix_setuid() |
Response
boolean
True if identity successfully changed
close
Method to close the application.
close(integer $code) : void
since |
1.0 |
---|
Arguments
- $code
integer
The exit code (optional; default is 0).
daemonize
Method to put the application into the background.
daemonize() : boolean
since |
1.0 |
---|---|
throws |
|
Response
boolean
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() : void
since |
1.0 |
---|---|
throws |
|
doExecute
Method to run the application routines. Most likely you will want to instantiate a controller and execute it, or perform some sort of task directly.
doExecute() : mixed
since |
1.0 |
---|
Response
mixed
execute
Execute the application.
execute() : void
since |
1.0 |
---|
fork
Method to fork the process.
fork() : integer
since |
1.0 |
---|---|
throws |
|
Response
integer
The 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() : void
since |
1.0 |
---|
get
Returns a property of the object or the default value if the property is not set.
get(string $key, mixed $default = null) : mixed
since |
1.0 |
---|
Arguments
- $key
string
The name of the property.- $default
mixed
The default value (optional) if none is set.
Response
mixed
The value of the configuration.
getCliInput
Get a CLI input object.
getCliInput() : \Joomla\Application\Cli\CliInput
getLogger
Get the logger.
getLogger() : \Psr\Log\LoggerInterface
since |
1.0 |
---|
Response
\Psr\Log\LoggerInterface
getOutput
Get an output object.
getOutput() : \Joomla\Application\Cli\CliOutput
in
Get a value from standard input.
in() : string
since |
1.0 |
---|
Response
string
The input string from standard input.
initialise
Custom initialisation method.
initialise() : void
Called at the end of the AbstractApplication::__construct method. This is for developers to inject initialisation code for their application classes.
since |
1.0 |
---|
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() : boolean
since |
1.0 |
---|
Response
boolean
True if daemon is active.
loadConfiguration
Load an object or array into the application configuration object.
loadConfiguration(mixed $data) : \Joomla\Application\AbstractDaemonApplication
since |
1.0 |
---|
Arguments
- $data
mixed
Either an array or object to be loaded into the configuration object.
Response
\Joomla\Application\AbstractDaemonApplication
Instance of $this to allow chaining.
out
Write a string to standard output.
out(string $text = '', boolean $nl = true) : \Joomla\Application\AbstractCliApplication
since |
1.0 |
---|
Arguments
- $text
string
The text to display.- $nl
boolean
True (default) to append a new line at the end of the output string.
Response
\Joomla\Application\AbstractCliApplication
Instance of $this to allow chaining.
pcntlChildExitStatus
Method to return the exit code of a terminated child process.
pcntlChildExitStatus(integer $status) : integer
see | \Joomla\Application\pcntl_wexitstatus() |
---|---|
since |
1.0 |
Arguments
- $status
integer
The status parameter is the status parameter supplied to a successful call to pcntl_waitpid().
Response
integer
The child process exit code.
pcntlFork
Method to return the exit code of a terminated child process.
pcntlFork() : integer
see | \Joomla\Application\pcntl_fork() |
---|---|
since |
1.0 |
Response
integer
On 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(integer $signal, callable $handler, boolean $restart = true) : boolean
see | \Joomla\Application\pcntl_signal() |
---|---|
since |
1.0 |
Arguments
- $signal
integer
The signal number.- $handler
callable
The 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
boolean
Specifies whether system call restarting should be used when this signal arrives.
Response
boolean
True on success.
pcntlWait
Method to wait on or return the status of a forked child.
pcntlWait(integer &$status, integer $options) : integer
see | \Joomla\Application\pcntl_wait() |
---|---|
since |
1.0 |
Arguments
- $status
integer
Status information.- $options
integer
If wait3 is available on your system (mostly BSD-style systems), you can provide the optional options parameter.
Response
integer
The 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() : void
since |
1.0 |
---|
restart
Restart daemon process.
restart() : void
since |
1.0 |
---|
set
Modifies a property of the object, creating it if it does not already exist.
set(string $key, mixed $value = null) : mixed
since |
1.0 |
---|
Arguments
- $key
string
The name of the property.- $value
mixed
The value of the property to set (optional).
Response
mixed
Previous value of the property
setConfiguration
Sets the configuration for the application.
setConfiguration(\Joomla\Registry\Registry $config) : \Joomla\Application\AbstractApplication
since |
1.0 |
---|
Arguments
- $config
\Joomla\Registry\Registry
A registry object holding the configuration.
Response
\Joomla\Application\AbstractApplication
Returns itself to support chaining.
setLogger
Set the logger.
setLogger(\Psr\Log\LoggerInterface $logger) : \Joomla\Application\AbstractApplication
since |
1.0 |
---|
Arguments
- $logger
\Psr\Log\LoggerInterface
The logger.
Response
\Joomla\Application\AbstractApplication
Returns itself to support chaining.
setupSignalHandlers
Method to attach the AbstractDaemonApplication signal handler to the known signals. Applications can override these handlers by using the pcntl_signal() function and attaching a different callback method.
setupSignalHandlers() : boolean
since |
1.0 |
---|---|
see | \Joomla\Application\pcntl_signal() |
Response
boolean
shutdown
Method to shut down the daemon and optionally restart it.
shutdown(boolean $restart = false) : void
since |
1.0 |
---|
Arguments
- $restart
boolean
True to restart the daemon on exit.
signal
Method to handle POSIX signals.
signal(integer $signal) : void
since |
1.0 |
---|---|
see | \Joomla\Application\pcntl_signal() |
throws |
|
Arguments
- $signal
integer
The received POSIX signal.
stop
Stop daemon process.
stop() : void
since |
1.0 |
---|
writeProcessIdFile
Method to write the process id file out to disk.
writeProcessIdFile() : boolean
since |
1.0 |
---|
Response
boolean
Properties
signals
The available POSIX signals to be caught by default.
exiting
True if the daemon is in the process of exiting.
since |
1.0 |
---|
Type(s)
boolean
parentId
The parent process id.
since |
1.0 |
---|
Type(s)
integer
processId
The process id of the daemon.
since |
1.0 |
---|
Type(s)
integer
running
True if the daemon is currently running.
since |
1.0 |
---|
Type(s)
boolean
logger
A logger.
since |
1.0 |
---|
Type(s)
\Psr\Log\LoggerInterface