How to check if a php script is still running

前端 未结 13 2561
鱼传尺愫
鱼传尺愫 2020-12-15 12:02

I have a PHP script that listens on a queue. Theoretically, it\'s never supposed to die. Is there something to check if it\'s still running? Something like

13条回答
  •  甜味超标
    2020-12-15 12:49

    I had the same issue - wanting to check if a script is running. So I came up with this and I run it as a cron job. It grabs the running processes as an array and cycles though each line and checks for the file name. Seems to work fine. Replace #user# with your script user.

    exec("ps -U #user# -u #user# u", $output, $result);
    foreach ($output AS $line) if(strpos($line, "test.php")) echo "found";
    

提交回复
热议问题