How to check if a php script is still running

前端 未结 13 2575
鱼传尺愫
鱼传尺愫 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:52

    In linux run ps as follows:

    ps -C php -f
    

    You could then do in a php script:

    $output = shell_exec('ps -C php -f');
    if (strpos($output, "php my_script.php")===false) { 
      shell_exec('php my_script.php  > /dev/null 2>&1 &');
    }
    

    The above code lists all php processes running in full, then checks to see if "my_script.php" is in the list of running processes, if not it runs the process and does not wait for the process to terminate to carry on doing what it was doing.

提交回复
热议问题