Sonzai Posted October 11, 2013 Share Posted October 11, 2013 Hi guys, Like the title says, for some reason SIGINT is not being caught and ending the process when it is sent. <?php define('logdir', '/var/www/html/Project2'); $pid = getmypid(); function catch_sigint($sig_num) { print('got a signal sigint\n'); flush(STDOUT); pcntl_signal(SIGINT, "catch_sigint"); posix_kill($pid, SIGINT); exit(1); } if((count($argc) < 1 )||(count($argc) >=2)) { print("usage: webserver idcode"); exit(1); } pcntl_signal(SIGINT, "catch_sigint"); while(1) { print "running"; sleep(3); } ?> If it's any insight, I had an interesting problem with getting the pid - I originally tried posix_getpid() but it gave an error saying that it was undefined though I'm running this on a Linux machine. The webserver env. is Apache. Thanks for any and all help! Quote Link to comment Share on other sites More sharing options...
kicken Posted October 11, 2013 Share Posted October 11, 2013 As of PHP 4.3.0 PCNTL uses ticks as the signal handle callback mechanism, which is much faster than the previous mechanism. This change follows the same semantics as using "user ticks". You must use the declare() statement to specify the locations in your program where callbacks are allowed to occur for the signal handler to function properly (as used in the above example). Quote Link to comment Share on other sites More sharing options...
requinix Posted October 11, 2013 Share Posted October 11, 2013 You can also do a pcntl_signal_dispatch after the sleep: SIGINT will interrupt the sleep but not be acted upon unless you dispatch or use ticks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.