This package is abandoned and no longer maintained. No replacement package was suggested.

A PHP framework for writing (forked) multi process daemons

dev-master 2014-09-09 12:39 UTC

This package is not auto-updated.

Last update: 2020-01-24 15:17:21 UTC


Beelzebub is a PHP framework for writing (forked) multi process daemons. It provides a highly configurable process manager, an extend-able logging and a simple programming interface.

If you are looking for a single process daemon framework, have a look at clio.



require_once 'vendor/autoload.php';

use Fortrabbit\Beelzebub\DaemonInterface;
use Fortrabbit\Beelzebub\Daemon;
use Fortrabbit\Beelzebub\WorkerInterface;

$daemon = new Daemon("simple", "1.0.0");
    'do-something' => array(
        'run' => function (WorkerInterface &$w, DaemonInterface &$d) {
            $d->getLogger()->info("Doing something");
        'interval' => 30
    'do-something-else' => array(
        'startup' => function(WorkerInterface &$worker, DaemonInterface &$d) {
            $d->getLogger()->info("Staring up something else");
        'run' => function (WorkerInterface &$w, DaemonInterface &$d) {
            $d->getLogger()->info("Doing something else");
        'interval' => 5,




$ php composer.phar require "fortrabbit/beelzebub:@dev"




// create a new daemon instance with name and version
$daemon = new Daemon("simple", "1.0.0");

Register worker


// register worker by name

    // unique name of the worker
    'worker-name' => array(

        // opt: startup method, called before first run
        'startup' => function (WorkerInterface &$w, DaemonInterface &$d) {
            // ..

        // req: the run method, called every [interval]
        'run' => function (WorkerInterface &$w, DaemonInterface &$d) {
            // ..

        // req: the interval between calling the run in seconds
        'interval' => 30,

        // opt: amount of instances (default: 1)
        'amount' => 2
    // .. other workers

// de-register a named worker

Shutdown behavior


// set shutdown method in seconds. Defaults to 30

// set alternate shutdown signal which is sent to workers. Default: SIGQUIT

// set callback for when every child has been killed
$daemon->setShutdownHandler(function (DaemonInterface &$d) { /*..*/ });

Restart behavior


// enable restart (stop/start) of all workers on signal. Use false to
//  deactivate again (default)

// set handler which is called when stop of all workers is performed, right
//  before start is executed. Only used if restart signal has been set.
$daemon->setRestartHandler(function (DaemonInterface &$d) { /* .. */ });


Per default, everything is logged to STDOUT.


// set an logfile for output.

// set a \Monolog\Logger for handling logging (above logfile is ignored, if
//  this is used)

// access to logger



// run daemon, do NOT detach from shell

// run daemon and DO detach from shell. Write pid into $pidFile



// sleep entropy introduces randomness. A value of 0 indicates no randomness,
//  a value of 100 the maximum.
//  Example: if the interval attrib of a worker is set to 30.
//    entropy = 0:   the process manager waits exactly 30 seconds between worker loops
//    entropy = 50:  the process manager waits 15 to 45 seconds between worker loops
//    entropy = 100: the process manager waits 0 to 60 seconds between worker loops
//  Default is 50


  • Untested on PHP 5.3, but should work