We would like to check if a specified process is currently running via PHP.
We would like to simply supply a PID and see if it is currently executing or not.
Does PHP have an internal function that would give us this information or do we have to parse it out of "ps" output?
The easiest way to find out if process is running is run ps aux command and grep process name. If you got output along with process name/pid, your process is running.
Check if a PHP script is already running If you have long running batch processes with PHP that are run by cron and you want to ensure there's only ever one running copy of the script, you can use the functions getmypid() and posix_kill() to check to see if you already have a copy of the process running.
If you are on Linux, try this :
if (file_exists( "/proc/$pid" )){ //process with a pid = $pid is running }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With