I have a web script that takes a really long time to run (and it's supposed to take a long time). By "web script" I mean a script that's run by visiting a page in a browser and opposed to executed on the command line. The script is in PHP and I'm on a LAMP stack.
How can I find and kill this process if I want to?
"Kill" might be the wrong word. I just want the script to stop. I could conceivably make this script "watch" for some state of my system to change, and then halt when it notices that change. If I do that, I'm not sure what the best way to do that would be. In any case, I'm completely open to any suggestions.
When the script starts, write its pid to a file, something like
file_put_contents(getmypid ().".pid","Running");
And when the script is done, it deletes the file.
You then create another script that will run form cron. It looks for pid files over a certain age, and does a kill $pid
on them
Simple.