Download the PHP package phlib/console-process without Composer
On this page you can find all versions of the php package phlib/console-process. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package console-process
phlib/console-process
Console signal implementation using PHPs Process control functions.
There are 2 implementations.
- Background command. Repeatedly execute a command, until interrupted using the signal handler.
- Daemon command. Builds on the Background command to allow forking (detaching) the process.
Install
Via Composer
Background Command
Basic Usage
The Background Command is implemented in the same way as you're used to with the
normal Symfony Command, however it must allow for the execute()
method to be
called multiple times.
There is a processing delay between each execution which can be customised.
Stopping execution
Normal usage
Typically, the command will continue execution until interrupted by a signal,
e.g. a user pressing Ctrl+C
.
Self-termination
Alternatively, if an implementation has a finite task, for example deleting
records in batches, it may need to terminate itself once the task is complete.
This is done by calling shutdown()
.
Non-zero exit
If an execution returns a non-zero exit code, iteration will be stopped and the exit code will be passed back to the console, as with a normal Symfony Command.
Lifecycle Methods
The background command has additional methods that get called when the process starts and finishes. Useful for any initialising or final cleanup.
onStart(InputInterface $input, OutputInterface $output): void
- Similar to standard
initialize()
; useful forDaemonCommand
.
- Similar to standard
onShutdown(InputInterface $input, OutputInterface $output): void
onException(\Exception $e, InputInterface $input, OutputInterface $output): void
Daemon Command
Basic Usage
Apart from extending a different class, the Daemon Command looks and works in a similar way to the Background Command. The PID file argument is optional. If it is not specified the process generates it's own PID file based on the command name.
Output
Once a daemon process is detached, the original output is also lost.
The --child-log | -o
option can be used to specify a filename to write output.
Alternatively, the createChildOutput()
method can be overridden to return a
new output instance. For example:
Lifecycle Methods
The daemon command has additional methods, to the standard Symfony command methods and the background command, which gets called during the process lifecycle. The following example demonstrates overriding the methods.
Command Line
Options
Name | Short | Type | Required | Default | Description |
---|---|---|---|---|---|
action | Argument | yes | start, stop, status | ||
daemonize | d | Option | no | no | Detaches the process |
pid-file | p | Option | no | auto | Name of the PID file to use. Not used if daemonize is not set. |
child-log | o | Option | no | no | Name of the file to save child output. Not used if daemonize is not set. |
License
This package is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this program. If not, see http://www.gnu.org/licenses/.