Skip to content

Instantly share code, notes, and snippets.

@mmohiudd
Created September 5, 2013 17:51
Show Gist options
  • Save mmohiudd/6453664 to your computer and use it in GitHub Desktop.
Save mmohiudd/6453664 to your computer and use it in GitHub Desktop.
testing SIGNALs with circusd
[circus]
check_delay = 5
endpoint = tcp://127.0.0.1:5555
pubsub_endpoint = tcp://127.0.0.1:5556
;stats_endpoint = tcp://127.0.0.1:5557
httpd = False
debug = False
[plugin:flapping]
use = circus.plugins.flapping.Flapping
retry_in = 3
max_retry = 2
[watcher:sigtest]
cmd=/mnt/giant/sigtest.php
uid=root
numprocesses=1
priority=14
#!/usr/bin/php
<?php
ini_set("error_reporting",E_ALL);
ini_set("display_errors",1);
function _log($message, $echo=false){
$pid = getmypid();
$log_message = "[$pid][" . date("Y-m-d H:i:s") . "] $message\n";
file_put_contents("/var/log/sigtest.log", $log_message, FILE_APPEND);
echo $log_message;
}
// tick use required as of PHP 4.3.0
declare(ticks = 1);
// signal handler function
function sig_handler($signo) {
$pid = getmypid();
switch ($signo) {
case SIGTERM:
// handle shutdown tasks
_log("Caught SIGTERM");
exit;
break;
case SIGINT:
_log("Caught SIGINT");
exit;
break;
case SIGHUP:
_log("Caught SIGHUP");
break;
default:
echo "Something else received\n";
break;
}
}
_log("Installing signal handler");
// setup signal handlers
pcntl_signal(SIGTERM, "sig_handler");
pcntl_signal(SIGINT, "sig_handler");
pcntl_signal(SIGHUP, "sig_handler");
while(1){
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment