okok
09-11-2004, 05:53 AM
I have a PHP script that can run for hours. Is there any way I can stop it using another script?
![]() | View Full Version : Can php stop another running php script? okok 09-11-2004, 05:53 AM I have a PHP script that can run for hours. Is there any way I can stop it using another script? Burhan 09-11-2004, 06:11 AM Not very easily. To stop a script, you would have to kill its process, which requires elevated permissions. PHP scripts have a default timeout (I believe 30 seconds). If you really need to kill a script process, use suexec. okok 09-11-2004, 06:17 AM Thank you. lwknet 09-11-2004, 09:25 PM this is not easy for a purely phper, but is the easiest way i can thk of 1) fork a child (or multiple children at once) to do the dirty job 2) remember the pid of your child/children 3) set a rule to catch the SIGCLD so that the parent knows when child finishes his job with his pid 4) the parent sleep for say 3600 secs to wait for all children finish or all children pids have been caught 5) if not all pids have been caught in 3600 secs, your parent wakes up, you know something is going wrong, communicate with that child in your own way to see if the parent needs to wait longer for his process or you can do the reverse, fork a child to monitor the parent, the child sleeps for say 600 secs and closes itself so when the parent catches the SIGCLD it knows 600 secs pass, but this can't be multi-threaded all of the above can not be used with apache, apache will SIGHUP your script no matter what if 300 secs pass |