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\Input input = null, \Joomla\Registry\Registry config = null) : mixed
| since |
3.0.0 |
|---|
Arguments
- input
\Joomla\CMS\Input\InputAn optional argument to provide dependency injection for the application's input object. If the argument is a \JInput object that object will become the application's input object, otherwise a default input object is created.- config
\Joomla\Registry\RegistryAn 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.
Response
mixed
changeIdentity
Method to change the identity of the daemon process and resources.
changeIdentity() : bool
| since |
1.7.0 |
|---|---|
| see | posix_setuid() |
Response
boolTrue if identity successfully changed
daemonize
Method to put the application into the background.
daemonize() : bool
| 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() : void
| since |
3.0.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() : void
| since |
3.4 |
|---|---|
| deprecated |
4.0 The default concrete implementation of doExecute() will be removed, subclasses will need to provide their own implementation. |
execute
Execute the application.
execute() : void
| since |
1.7.0 |
|---|
fetchConfigurationData
Method to load a PHP configuration class file based on convention and return the instantiated data object. You will extend this method in child classes to provide configuration data from whatever data source is relevant for your specific application.
fetchConfigurationData(string file = '', string class = '\JConfig') : mixed
| since |
1.7.0 |
|---|
Arguments
- file
stringThe path and filename of the configuration file. If not provided, configuration.php in JPATH_CONFIGURATION will be used.- class
stringThe class name to instantiate.
Response
mixedEither an array or object to be loaded into the configuration object.
fork
Method to fork the process.
fork() : int
| 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() : void
| since |
1.7.0 |
|---|
getIdentity
Get the application identity.
getIdentity() : mixed
| since |
3.0.0 |
|---|
Response
mixedA \JUser object or null.
getInstance
Returns a reference to the global CliApplication object, only creating it if it doesn't already exist.
getInstance(string name = null) : \Joomla\CMS\Application\CliApplication
This method must be invoked as: $cli = CliApplication::getInstance();
| since |
1.7.0 |
|---|
Arguments
- name
stringThe name (optional) of the JApplicationCli class to instantiate.
Response
\Joomla\CMS\Application\CliApplication
getOutput
Get an output object.
getOutput() : \Joomla\Application\Cli\CliOutput
| since |
3.3 |
|---|
Response
\Joomla\Application\Cli\CliOutput
in
Get a value from standard input.
in() : string
| since |
1.7.0 |
|---|
Response
stringThe input string from standard input.
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() : bool
| since |
1.7.0 |
|---|
Response
boolTrue if daemon is active.
loadConfiguration
Load an object or array into the application configuration object.
loadConfiguration(mixed data) : \Joomla\CMS\Application\CliApplication
| since |
1.7.0 |
|---|
Arguments
- data
mixedEither an array or object to be loaded into the configuration object.
Response
\Joomla\CMS\Application\CliApplicationInstance of $this to allow chaining.
loadDispatcher
Allows the application to load a custom or default dispatcher.
loadDispatcher(\JEventDispatcher dispatcher = null) : \Joomla\CMS\Application\BaseApplication
The logic and options for creating this object are adequately generic for default cases but for many applications it will make sense to override this method and create event dispatchers, if required, based on more specific needs.
| since |
3.0.0 |
|---|
Arguments
- dispatcher
\JEventDispatcherAn optional dispatcher object. If omitted, the factory dispatcher is created.
Response
\Joomla\CMS\Application\BaseApplicationThis method is chainable.
loadIdentity
Allows the application to load a custom or default identity.
loadIdentity(\JUser identity = null) : \Joomla\CMS\Application\BaseApplication
The logic and options for creating this object are adequately generic for default cases but for many applications it will make sense to override this method and create an identity, if required, based on more specific needs.
| since |
3.0.0 |
|---|
Arguments
- identity
\JUserAn optional identity object. If omitted, the factory user is created.
Response
\Joomla\CMS\Application\BaseApplicationThis method is chainable.
out
Write a string to standard output.
out(string text = '', bool nl = true) : \Joomla\CMS\Application\CliApplication
| since |
1.7.0 |
|---|
Arguments
- text
stringThe text to display.- nl
boolTrue (default) to append a new line at the end of the output string.
Response
\Joomla\CMS\Application\CliApplicationInstance of $this to allow chaining.
pcntlChildExitStatus
Method to return the exit code of a terminated child process.
pcntlChildExitStatus(int status) : int
| 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() : int
| 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(int signal, callable handler, bool restart = true) : bool
| 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(int &status, int options) : int
| 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() : void
| since |
3.0.0 |
|---|
registerEvent
Registers a handler to a particular event group.
registerEvent(string event, callable handler) : \Joomla\CMS\Application\BaseApplication
| since |
3.0.0 |
|---|
Arguments
- event
stringThe event name.- handler
callableThe handler, a function or an instance of an event object.
Response
\Joomla\CMS\Application\BaseApplicationThe application to allow chaining.
restart
Restart daemon process.
restart() : void
| since |
1.7.0 |
|---|
setOutput
Set an output object.
setOutput(\Joomla\Application\Cli\CliOutput output) : \Joomla\CMS\Application\CliApplication
| since |
3.3 |
|---|
Arguments
- output
\Joomla\Application\Cli\CliOutputCliOutput object
Response
\Joomla\CMS\Application\CliApplicationInstance of $this to allow chaining.
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() : bool
| since |
1.7.0 |
|---|---|
| see | pcntl_signal() |
Response
bool
shutdown
Method to shut down the daemon and optionally restart it.
shutdown(bool restart = false) : void
| since |
1.7.0 |
|---|
Arguments
- restart
boolTrue to restart the daemon on exit.
signal
Method to handle POSIX signals.
signal(int signal) : void
| since |
1.7.0 |
|---|---|
| see | pcntl_signal() |
| throws |
|
Arguments
- signal
intThe received POSIX signal.
stop
Stop daemon process.
stop() : void
| since |
1.7.0 |
|---|
triggerEvent
Calls all handlers associated with an event group.
triggerEvent(string event, array args = null) : array
| since |
3.0.0 |
|---|
Arguments
- event
stringThe event name.- args
arrayAn array of arguments (optional).
Response
arrayAn array of results from each function call, or null if no dispatcher is defined.
writeProcessIdFile
Method to write the process id file out to disk.
writeProcessIdFile() : bool
| 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
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
output
The output type.
| since |
3.3 |
|---|
Type(s)
\Joomla\Application\Cli\CliOutput
instance
The application instance.
| since |
1.7.0 |
|---|
Type(s)
\Joomla\CMS\Application\CliApplication
dispatcher
The application dispatcher object.
| since |
3.0.0 |
|---|
Type(s)
\JEventDispatcher
identity
The application identity object.
| since |
3.0.0 |
|---|
Type(s)
\JUser
input
The application input object
Type(s)
\JInput