Example #1
0
    foreach ($runmode as $runmod => $val) {
        echo " --" . $runmod . "\n";
    }
    die;
}
// Make it possible to test in source directory
// This is for PEAR developers only
ini_set('include_path', ini_get('include_path') . ':..');
// Include Class
error_reporting(E_ALL);
require_once "System/Daemon.php";
// Setup
$options = array("appName" => "mercury", "appDir" => dirname(__FILE__), "appDescription" => "Informs the user of their social interactions.", "authorName" => "Alastair Dewar", "authorEmail" => "*****@*****.**", "sysMaxExecutionTime" => "0", "sysMaxInputTime" => "0", "sysMemoryLimit" => "256M", "appRunAsGID" => 1000, "appRunAsUID" => 1000);
System_Daemon::setOptions($options);
// Overrule the signal handler with any function
System_Daemon::setSigHandler(SIGCONT, array("System_Daemon", "defaultSigHandler"));
// This program can also be run in the forground with runmode --no-daemon
if (!$runmode["no-daemon"]) {
    // Spawn Daemon
    System_Daemon::start();
}
// With the runmode --write-initd, this program can automatically write a
// system startup file called: 'init.d'
// This will make sure your daemon will be started on reboot
if (!$runmode["write-initd"]) {
    System_Daemon::log(System_Daemon::LOG_INFO, "not writing " . "an init.d script this time");
} else {
    if (($initd_location = System_Daemon::writeAutoRun()) === false) {
        System_Daemon::log(System_Daemon::LOG_NOTICE, "unable to write " . "init.d script");
    } else {
        System_Daemon::log(System_Daemon::LOG_INFO, "sucessfully written " . "startup script: " . $initd_location);
 * In panic situations, you can always kill you daemon by typing
 * 
 * killall -9 signals.php
 * OR:
 * killall -9 php
 */
// Make it possible to test in source directory
// This is for PEAR developers only
ini_set('include_path', ini_get('include_path') . ':..');
// Include Class
error_reporting(E_ALL);
require_once 'System/Daemon.php';
// Setup
System_Daemon::setOptions(array('appName' => 'signals', 'appDir' => dirname(__FILE__), 'appDescription' => 'Showcases how you could catch POSIX signals', 'authorName' => 'Kevin van Zonneveld', 'authorEmail' => '*****@*****.**', 'sysMaxExecutionTime' => '0', 'sysMaxInputTime' => '0', 'sysMemoryLimit' => '1024M', 'appRunAsGID' => 1000, 'appRunAsUID' => 1000));
// Overrule the signal handler with any function
System_Daemon::setSigHandler(SIGTERM, 'myHandler');
function myHandler($signal)
{
    if ($signal === SIGTERM) {
        System_Daemon::warning('I received the termination signal. ' . $sig);
        // Execute some final code
        // and be sure to:
        System_Daemon::stop();
    }
}
// Spawn Daemon
System_Daemon::start();
// Here comes your own actual code
// This variable keeps track of how many 'runs' or 'loops' your daemon has
// done so far. For example purposes, we're quitting on 3.
$cnt = 1;