Class JApplicationDaemon
Class to turn JApplicationCli applications into daemons. It requires CLI and
PCNTL support built into PHP.
-
Joomla\Application\AbstractApplication
implements
Psr\Log\LoggerAwareInterface
-
JApplicationBase
-
JApplicationCli
-
JApplicationDaemon
Methods summary
public
|
#
__construct( JInputCli $input = null, Joomla\Registry\Registry $config = null, JEventDispatcher $dispatcher = null )
Class constructor.
Parameters
- $input
JInputCli - $input An 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
Joomla\Registry\Registry - $config 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.
- $dispatcher
JEventDispatcher - $dispatcher An optional argument to provide dependency injection for the
application's event dispatcher. If the argument is a JEventDispatcher 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.
Throws
Since
11.1
Overrides
|
public static
|
#
signal( integer $signal )
Method to handle POSIX signals.
Method to handle POSIX signals.
Parameters
- $signal
integer - $signal The received POSIX signal.
Throws
Since
11.1
See
pcntl_signal()
|
public
boolean
|
#
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.
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.
Returns
boolean - True if daemon is active.
Since
11.1
|
public
JCli
|
#
loadConfiguration( mixed $data )
Load an object or array into the application configuration object.
Load an object or array into the application configuration object.
Parameters
- $data
mixed - $data Either an array or object to be loaded into the configuration object.
Returns
JCli
- Instance of $this to allow chaining.
Since
11.1
Overrides
|
public
|
#
execute( )
Execute the daemon.
Since
11.1
Overrides
|
public
|
#
restart( )
Restart daemon process.
Since
11.1
CodeCoverageIgnore
|
public
|
#
stop( )
Stop daemon process.
Since
11.1
CodeCoverageIgnore
|
protected
boolean
|
#
changeIdentity( )
Method to change the identity of the daemon process and resources.
Method to change the identity of the daemon process and resources.
Returns
boolean - True if identity successfully changed
Since
11.1
See
posix_setuid()
|
protected
boolean
|
#
daemonize( )
Method to put the application into the background.
Method to put the application into the background.
Returns
boolean
Throws
Since
11.1
|
protected
|
#
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.
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.
Throws
Since
12.1
|
protected
integer
|
#
fork( )
Method to fork the process.
Method to fork the process.
Returns
integer - The child process id to the parent process, zero to the child process.
Throws
Since
11.1
|
protected
|
#
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.
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.
Since
11.1
CodeCoverageIgnore
|
protected
boolean
|
#
setupSignalHandlers( )
Method to attach the JApplicationDaemon signal handler to the known signals.
Applications can override these handlers by using the pcntl_signal() function
and attaching a different callback method.
Method to attach the JApplicationDaemon signal handler to the known signals.
Applications can override these handlers by using the pcntl_signal() function
and attaching a different callback method.
Returns
boolean
Since
11.1
See
pcntl_signal()
|
protected
|
#
shutdown( boolean $restart = false )
Method to shut down the daemon and optionally restart it.
Method to shut down the daemon and optionally restart it.
Parameters
- $restart
boolean - $restart True to restart the daemon on exit.
Since
11.1
|
protected
boolean
|
#
writeProcessIdFile( )
Method to write the process id file out to disk.
Method to write the process id file out to disk.
Returns
boolean
Since
11.1
|
protected
|
#
postFork( )
Method to handle post-fork triggering of the onFork event.
Method to handle post-fork triggering of the onFork event.
Since
12.1
|
protected
integer
|
#
pcntlChildExitStatus( integer $status )
Method to return the exit code of a terminated child process.
Method to return the exit code of a terminated child process.
Parameters
- $status
integer - $status The status parameter is the status parameter supplied to a successful
call to pcntl_waitpid().
Returns
integer - The child process exit code.
Since
11.3
See
pcntl_wexitstatus()
CodeCoverageIgnore
|
protected
integer
|
#
pcntlFork( )
Method to return the exit code of a terminated child process.
Method to return the exit code of a terminated child process.
Returns
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.
Since
11.3
See
pcntl_fork()
CodeCoverageIgnore
|
protected
boolean
|
#
pcntlSignal( integer $signal, callable $handler, boolean $restart = true )
Method to install a signal handler.
Method to install a signal handler.
Parameters
- $signal
integer - $signal The signal number.
- $handler
callable - $handler 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 - $restart Specifies whether system call restarting should be used when this
signal arrives.
Returns
boolean - True on success.
Since
11.3
See
pcntl_signal()
CodeCoverageIgnore
|
protected
integer
|
#
pcntlWait( integer & $status, integer $options = 0 )
Method to wait on or return the status of a forked child.
Method to wait on or return the status of a forked child.
Parameters
- $status
integer - &$status Status information.
- $options
integer - $options If wait3 is available on your system (mostly BSD-style systems), you
can provide the optional options parameter.
Returns
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.
Since
11.3
See
pcntl_wait()
CodeCoverageIgnore
|
fetchConfigurationData()
,
getInstance()
,
getOutput()
,
in()
,
out()
,
setOutput()
doExecute()
,
getIdentity()
,
loadDispatcher()
,
loadIdentity()
,
registerEvent()
,
triggerEvent()
close()
,
get()
,
getLogger()
,
initialise()
,
set()
,
setConfiguration()
,
setLogger()
Magic methods summary
Properties summary
protected static
array
|
$signals
|
#
The available POSIX signals to be caught by default.
The available POSIX signals to be caught by default.
Since
11.1
Link
|
protected
boolean
|
$exiting
|
#
True if the daemon is in the process of exiting.
True if the daemon is in the process of exiting.
Since
11.1
|
protected
integer
|
$parentId
|
#
The parent process id.
Since
12.1
|
protected
integer
|
$processId
|
#
The process id of the daemon.
The process id of the daemon.
Since
11.1
|
protected
boolean
|
$running
|
#
True if the daemon is currently running.
True if the daemon is currently running.
Since
11.1
|
$instance
,
$output
$dispatcher
,
$identity
$config
,
$input
$input