System_Daemon

Because the Process Control Extensions' documentation is a bit rough, I decided to figure it out once, and then wrap my knowledge and the required code inside a PEAR class called: System_Daemon. And so now you can just:

System_Daemon Usage

<?php
    
require_once "System/Daemon.php";                 // Include the Class

    
System_Daemon::setOption("appName""mydaemon");  // Minimum configuration
    
System_Daemon::start();                           // Spawn Deamon!
?>

And that's all there is to it. The code after that, will run in your server's background. So next, if you create a while(true) loop around that code, the code will run indefinitely. Remember to build in a sleep(5) to ease up on system resources.

Features & Characteristics Here's a grab of System_Daemon's features:

  • Daemonize any PHP-CLI script

  • Simple syntax

  • Driver based Operating System detection

  • Unix only

  • Additional features for Debian / Ubuntu based systems like:

  • Automatically generate startup files (init.d)

  • Support for PEAR's Log package

  • Can run with PEAR (more elegance & functionality) or without PEAR (for standalone packages)

  • Default signal handlers, but optionally reroute signals to your own handlers.

  • Set options like max RAM usage

    Поддержать сайт на родительском проекте КГБ