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\Input\Input input = null, \Joomla\Registry\Registry config = null, \Joomla\CMS\Application\CLI\CliOutput output = null, \Joomla\CMS\Application\CLI\CliInput cliInput = null, \Joomla\Event\DispatcherInterface dispatcher = null, \Joomla\DI\Container container = null) : mixed
since |
1.7.0 |
---|
Arguments
- input
\Joomla\Input\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
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.- output
\Joomla\CMS\Application\CLI\CliOutput
The output handler.- cliInput
\Joomla\CMS\Application\CLI\CliInput
The CLI input handler.- dispatcher
\Joomla\Event\DispatcherInterface
An 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.- container
\Joomla\DI\Container
Dependency injection container.
Response
mixed
__get
Magic method to access properties of the application.
__get(string name) : mixed
since |
4.0.0 |
---|---|
deprecated |
4.0 will be removed in 6.0 This is a B/C proxy for deprecated read accesses Example: Factory::getApplication()->getInput(); |
Arguments
- name
string
The name of the property.
Response
mixed
A value if the property name is valid, null otherwise.
bootComponent
Boots the component with the given name.
bootComponent(string component) : \Joomla\CMS\Extension\ComponentInterface
since |
4.0.0 |
---|
Arguments
- component
string
The component to boot.
Response
\Joomla\CMS\Extension\ComponentInterface
bootModule
Boots the module with the given name.
bootModule(string module, string applicationName) : \Joomla\CMS\Extension\ModuleInterface
since |
4.0.0 |
---|
Arguments
- module
string
The module to boot- applicationName
string
The application name
Response
\Joomla\CMS\Extension\ModuleInterface
bootPlugin
Boots the plugin with the given name and type.
bootPlugin(string plugin, string type) : \Joomla\CMS\Extension\PluginInterface
since |
4.0.0 |
---|
Arguments
- plugin
string
The plugin name- type
string
The type of the plugin
Response
\Joomla\CMS\Extension\PluginInterface
changeIdentity
Method to change the identity of the daemon process and resources.
changeIdentity() : bool
since |
1.7.0 |
---|---|
see | posix_setuid() |
Response
bool
True if identity successfully changed
createExtensionNamespaceMap
Allows the application to load a custom or default identity.
createExtensionNamespaceMap() : void
since |
4.0.0 |
---|
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 |
|
enqueueMessage
Enqueue a system message.
enqueueMessage(string msg, string type = self::MSG_INFO) : void
since |
4.0.0 |
---|
Arguments
- msg
string
The message to enqueue.- type
string
The message type.
execute
Execute the application.
execute() : void
since |
1.7.0 |
---|
fork
Method to fork the process.
fork() : int
since |
1.7.0 |
---|---|
throws |
|
Response
int
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.7.0 |
---|
getCliInput
Get a CLI input object.
getCliInput() : \Joomla\CMS\Application\CLI\CliInput
since |
4.0.0 |
---|
Response
\Joomla\CMS\Application\CLI\CliInput
getConfig
Retrieve the application configuration object.
getConfig() : \Joomla\Registry\Registry
since |
4.0.0 |
---|
Response
\Joomla\Registry\Registry
getContainer
Get the DI container.
getContainer() : \Joomla\DI\Container
since |
4.0.0 |
---|---|
throws |
|
Response
\Joomla\DI\Container
getDispatcher
Get the event dispatcher.
getDispatcher() : \Joomla\Event\DispatcherInterface
since |
4.0.0 |
---|---|
throws |
|
Response
\Joomla\Event\DispatcherInterface
getIdentity
Get the application identity.
getIdentity() : \Joomla\CMS\User\User
since |
4.0.0 |
---|
Response
\Joomla\CMS\User\User
getInput
Method to get the application input object.
getInput() : \Joomla\Input\Input
since |
4.0.0 |
---|
Response
\Joomla\Input\Input
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 |
---|---|
deprecated |
4.0 will be removed in 6.0 Load the app through the container or via the Factory Example: Factory::getContainer()->get(CliApplication::class) |
throws |
|
Arguments
- name
string
The name (optional) of the Application Cli class to instantiate.
Response
\Joomla\CMS\Application\CliApplication
getLanguage
Method to get the application language object.
getLanguage() : \Joomla\CMS\Language\Language
since |
4.0.0 |
---|
Response
\Joomla\CMS\Language\Language
The language object
getLogger
Get the logger.
getLogger() : \Psr\Log\LoggerInterface
since |
4.0.0 |
---|
Response
\Psr\Log\LoggerInterface
getMessageQueue
Get the system message queue.
getMessageQueue() : array
since |
4.0.0 |
---|
Response
array
The system message queue.
getOutput
Get an output object.
getOutput() : \Joomla\CMS\Application\CLI\CliOutput
since |
4.0.0 |
---|
Response
\Joomla\CMS\Application\CLI\CliOutput
getSession
Method to get the application session object.
getSession() : \Joomla\Session\SessionInterface
since |
4.0.0 |
---|
Response
\Joomla\Session\SessionInterface
The session object
in
Get a value from standard input.
in() : string
since |
4.0.0 |
---|
Response
string
The 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
bool
True if daemon is active.
isCli
Flag if the application instance is a CLI or web based application.
isCli() : bool
Helper function, you should use the native PHP functions to detect if it is a CLI application.
since |
4.0.0 |
---|---|
deprecated |
4.0 will be removed in 6.0 Will be removed without replacements |
Response
bool
isClient
Check the client interface by name.
isClient(string identifier) : bool
since |
4.0.0 |
---|
Arguments
- identifier
string
String identifier for the application interface
Response
bool
True if this application is of the given type client interface.
loadConfiguration
Load an object or array into the application configuration object.
loadConfiguration(mixed data) : \Joomla\CMS\Application\DaemonApplication
since |
1.7.0 |
---|
Arguments
- data
mixed
Either an array or object to be loaded into the configuration object.
Response
\Joomla\CMS\Application\DaemonApplication
Instance of $this to allow chaining.
loadExtension
Loads the extension.
loadExtension(string type, string extensionName, string extensionPath) : \Joomla\CMS\Extension\ComponentInterface|\Joomla\CMS\Extension\ModuleInterface|\Joomla\CMS\Extension\PluginInterface
since |
4.0.0 |
---|
Arguments
- type
string
The extension type- extensionName
string
The extension name- extensionPath
string
The path of the extension
Response
\Joomla\CMS\Extension\ComponentInterface|\Joomla\CMS\Extension\ModuleInterface|\Joomla\CMS\Extension\PluginInterface
loadIdentity
Allows the application to load a custom or default identity.
loadIdentity(\Joomla\CMS\User\User identity = null) : $this
since |
4.0.0 |
---|
Arguments
- identity
\Joomla\CMS\User\User
An optional identity object. If omitted, a null user object is created.
Response
$this
loadPluginFromFilesystem
Creates a CMS plugin from the filesystem.
loadPluginFromFilesystem(string plugin, string type) : \Joomla\CMS\Plugin\CMSPlugin
since |
4.0.0 |
---|
Arguments
- plugin
string
The plugin- type
string
The type
Response
\Joomla\CMS\Plugin\CMSPlugin
out
Write a string to standard output.
out(string text = '', bool nl = true) : $this
since |
4.0.0 |
---|
Arguments
- text
string
The text to display.- nl
bool
True (default) to append a new line at the end of the output string.
Response
$this
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
int
The status parameter is the status parameter supplied to a successful call to pcntl_waitpid().
Response
int
The 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
int
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(int signal, callable handler, bool restart = true) : bool
see | pcntl_signal() |
---|---|
since |
1.7.3 |
Arguments
- signal
int
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
bool
Specifies whether system call restarting should be used when this signal arrives.
Response
bool
True 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
int
Status information.- options
int
If wait3 is available on your system (mostly BSD-style systems), you can provide the optional options parameter.
Response
int
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 |
3.0.0 |
---|
registerEvent
Registers a handler to a particular event group.
registerEvent(string event, callable handler) : $this
since |
4.0.0 |
---|
Arguments
- event
string
The event name.- handler
callable
The handler, a function or an instance of an event object.
Response
$this
restart
Restart daemon process.
restart() : void
since |
1.7.0 |
---|
setOutput
Set an output object.
setOutput(\Joomla\CMS\Application\CLI\CliOutput output) : $this
since |
3.3 |
---|
Arguments
- output
\Joomla\CMS\Application\CLI\CliOutput
CliOutput object
Response
$this
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
setUserFactory
Set the user factory to use.
setUserFactory(\Joomla\CMS\User\UserFactoryInterface userFactory) : void
since |
4.0.0 |
---|
Arguments
- userFactory
\Joomla\CMS\User\UserFactoryInterface
The user factory to use
shutdown
Method to shut down the daemon and optionally restart it.
shutdown(bool restart = false) : void
since |
1.7.0 |
---|
Arguments
- restart
bool
True 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
int
The received POSIX signal.
stop
Stop daemon process.
stop() : void
since |
1.7.0 |
---|
triggerEvent
Calls all handlers associated with an event group.
triggerEvent(string eventName, array|\Joomla\Event\Event args = []) : array
This is a legacy method, implementing old-style (Joomla! 3.x) plugin calls. It's best to go directly through the Dispatcher and handle the returned EventInterface object instead of going through this method. This method is deprecated and will be removed in Joomla! 5.x.
This method will only return the 'result' argument of the event
since |
4.0.0 |
---|---|
throws |
|
deprecated |
4.0 will be removed in 6.0 Use the Dispatcher method instead Example: Factory::getApplication()->getDispatcher()->dispatch($eventName, $event); |
Arguments
- eventName
string
The event name.- args
array|\Joomla\Event\Event
An array of arguments or an Event object (optional).
Response
array
An array of results from each function call. Note this will be an empty array if no dispatcher is set.
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
Output object
since |
4.0.0 |
---|
Type(s)
\Joomla\CMS\Application\CLI\CliOutput
input
The input.
since |
4.0.0 |
---|
Type(s)
\Joomla\Input\Input
cliInput
CLI Input object
since |
4.0.0 |
---|
Type(s)
\Joomla\CMS\Application\CLI\CliInput
language
The application language object.
since |
4.0.0 |
---|
Type(s)
\Joomla\CMS\Language\Language
messages
The application message queue.
since |
4.0.0 |
---|
Type(s)
array
instance
The application instance.
since |
1.7.0 |
---|
Type(s)
\Joomla\CMS\Application\CliApplication
identity
The application identity object.
since |
4.0.0 |
---|
Type(s)
\Joomla\CMS\User\User
userFactory
UserFactoryInterface
since |
4.0.0 |
---|
Type(s)
\Joomla\CMS\User\UserFactoryInterface