Download the PHP package seankndy/daemon without Composer
On this page you can find all versions of the php package seankndy/daemon. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package daemon
Installing
Usage overview
On each iteration of the main loop, producers are called which should provide a task to fork/run.
Producers can be callables or objects that implement SeanKndy\Daemon\Tasks\Producer
. Producers should return null
if there is no task to perform otherwise a SeanKndy\Daemon\Tasks\Task
or callable
. SeanKndy\Daemon\Tasks\Task
has 3 methods:
init()
- Called from parent process just before child is forked.
run()
- Called from within forked process (child work)
finish(int $status)
- Called from parent when process exits
So if you need to perform any initialization or teardown of as children are spawned/exiting, then
you'll want to make your own task classes implementing SeanKndy\Daemon\Tasks\Task
rather than using
a simple closure.
There are various events you can listen for (use SeanKndy\Daemon\Daemon::addListener()
):
SeanKndy\Daemon\DaemonEvent::START
- When daemon starts
SeanKndy\Daemon\DaemonEvent::STOP
- When daemon stops
SeanKndy\Daemon\DaemonEvent::DAEMONIZED
- When daemonized (backgrounded)
SeanKndy\Daemon\DaemonEvent::LOOP_ITERATION
- Called at the end of each loop iteration
SeanKndy\Daemon\Processes\Event::START
- New process started
SeanKndy\Daemon\Processes\Event::EXIT
- New process exited
SeanKndy\Daemon\Processes\Event::ITERATION
- Every main loop iteration this is fired for each running process
Inter-process Communication example
You can use \SeanKndy\Daemon\IPC\Socket
to send message from child to parent using socket pairs.
Here is an example of doing that:
All versions of daemon with dependencies
clue/socket-raw Version >=1.3
symfony/event-dispatcher Version ^4.1
psr/log Version ^3.0