How to check if a php script is still running

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

    Not for windows, but...

    I've got a couple of long-running PHP scripts, that have a shell script wrapping it. You can optionally return a value from the script that will be checked in the shell-script to exit, restart immediately, or sleep for a few seconds -and then restart.

    Here's a simple one that just keeps running the PHP script till it's manually stopped.

    #!/bin/bash
    clear
    date
    php -f cli-SCRIPT.php
    echo "wait a little while ..."; sleep 10
    exec $0

    The "exec $0" restarts the script, without creating a sub-process that will have to unravel later (and take up resources in the meantime). This bash script wraps a mail-sender, so it's not a problem if it exits and pauses for a moment.

提交回复
热议问题