Re: Killing a process with php

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



chris@xxxxxxxxxxxx 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/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux