I have scheduled a CRON which calls/executes a PHP script every five minutes. PHP script perform following tasks
All works fine so far, depending on the size of user uploaded data the process on an average takes 35 to 40 minutes to complete.
Question, Is there anyway to kill or stop the execution of PHP script once started by cron. May be a button to let users stop the execution, upload new data and wait for CRON run. I can take care of reseting all the flags and data it's just the kill of PHP script is what i am trying to figure out.
I did some google and figured i can use some commands like:
Killall -9 PHP
to kill all php processes running on server, but not sure how to do this through PHP.
Usage: ./cron. php activate to enable the cronjob and ./cron. php deactivate to disable it. The script sets the EDITOR environment variable properly (to itself) and then calls crontab -e , which on its turn calls the EDITOR (which is now the same cron.
if you need to stop a script in a windows environment, there is a taskkill command that you can run at a prompt; see computerhope.com/taskkill.htm.
Stop a cron job You can stop a single cron job by removing its line from the crontab file. To do that, run the crontab -e command and then delete the line for the specific task. Alternatively, you can stop the cron job by commenting it out in the crontab file.
Try this:
ps aux |grep 'part_of_the_name_of_your_script'|awk '{print $2}' |xargs kill -9 {}
Or in your crontab file use crun and variable CRUN_TIME
see crun -h
You can try system()
or exec()
, but it might not work (or return permission denied errors) as cron processes are executed by either the current user or root, and the web server user doesn't usually have access to these processes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With