Created
July 17, 2013 15:24
-
-
Save coldclimate/6021613 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Don't forget this line or signal handling won't work: | |
declare(ticks = 1); | |
// This global flag is used to trigger a configuration file reload. | |
$load_config = true; | |
// The SIGHUP handler doesn't do any actual work; it just sets the flag. | |
function handle_hup($signal) { | |
global $load_config; | |
$load_config = true; | |
pcntl_signal(SIGHUP, 'handle_hup', false); | |
} | |
// Register the signal handler. | |
pcntl_signal(SIGHUP, 'handle_hup', false); | |
// Start the service. | |
echo "myserver: starting service\n"; | |
while (true) { | |
// Load the config file if necessary. | |
if ($load_config) { | |
$load_config = false; | |
echo "myserver: loading configuration\n"; | |
include 'config.php'; | |
} | |
// Do something useful. | |
// ... | |
// Pause for a configurable amount of time. | |
echo "myserver: sleeping for $SLEEP_TIME seconds...\n"; | |
sleep($SLEEP_TIME); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment