Skip to content
emden-norfolk/php-daemon: Run a PHP script as a daemonised process.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

PHP Daemoniser

Daemonises PHP scripts with graceful shutdown and multiple workers.


How to write your scripts.

The following rules must be adheared to when writing a PHP script to be called by phpdaemon:

  • Your script must implement a function main().
  • Your script must check running() for a true/false condition for each item of work. If false, the script should exit. If you do not check for this condition, the script will be unable to exit cleanly and signal interrupts will be ignored.
  • Standard output is closed. Any use of print, echo, var_dump, etc will result in the script terminating abruptly.
  • Errors will be logged to a log file. Use trigger_error() to manually write to the log.

See examples/basic.php for an implementation reference.


./phpdaemon <php file> <process id file> <log file> <worker number>


./phpdaemon examples/basic.php example.log 0


Example of how to configure Monit with two workers. Assumes user is apache and directory is /opt.

check process example0 with pidfile /opt/daemon/
    start program = "/opt/daemon/phpdaemon /opt/daemon/examples/basic.php /opt/daemon/ /opt/daemon/example.log 0"
        as uid apache and gid apache
    stop program = "/opt/daemon/phpdaemonstop /opt/daemon/"

check process example1 with pidfile /opt/daemon/
    start program = "/opt/daemon/phpdaemon /opt/daemon/examples/basic.php /opt/daemon/ /opt/daemon/example.log 1"
        as uid apache and gid apache
    stop program = "/opt/daemon/phpdaemonstop /opt/daemon/"

Monit and Laravel

See examples/laravel/


You can’t perform that action at this time.