Re: Killing a process with php
| From: | Myron Turner | Date: | Wed, 09 May 2007 12:48:05 +0000 |
| Subject: | Re: Killing a process with php | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-254639@lists.php.net to get a copy of this message | ||
chris@aquanuke.com wrote:
Hi could someone give me examples on how to detect and kill processes on linux. I have a number of scripts running as socketxxx.php these stop and start every hour. But I also need to at the end of each day make sure their dead before the next days start. These processes are also running as root user. Thanks One way to do this would be to let the script check itself:<?php $end_of_day = mktime(23, 59, 59); declare(ticks = 1); function signal_handler($signal) {
$tm = time();
if($tm > $end_of_day) {
exit(0);
}
}
pcntl_signal(SIGALRM, "signal_handler", true);
pcntl_alarm(300);
?>
Here you set an alarm that checks every 5 minutes to see if the current timestamp is greater than the timestamp a minute before midnight. If it is, then exit. Or set a flag in the signal handler that is accessed elsewhere in your script which tells the script that it's time to exit.
--
_____________________
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/