Friday, January 14, 2022

[FIXED] How to kill a web process

Issue

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.


Solution

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.



Answered By - Byron Whitlock

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.