phpajaxfindscriptinghung

Finding/Handling stalled PHP scripts


I use Ajax to kick off a PHP script that can take a few hours to run. It's done asynchronously so the PHP script will complete even if the browser is closed.

I need to handle any of these PHP scripts that have stalled/hung for whatever reason. What is the best way to go about this? Is there a way to get a process id for the PHP script that can be used to check for activity periodically? I need to kill any outstanding scripts before starting a new one.

Thanks, Brian


Solution

  • A solution might be based on this idea :

    When another process is launched, it can check if that file is present :

    About detecting whether a process is running, and eventually killing it, I'm not sure if PHP provides that kind of functionnalities... It might be necessary to use exec to call command-line utilities like ps and kill...