Skip to content

Instantly share code, notes, and snippets.

@coldclimate
Created July 17, 2013 15:24
Show Gist options
  • Save coldclimate/6021613 to your computer and use it in GitHub Desktop.
Save coldclimate/6021613 to your computer and use it in GitHub Desktop.
// 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