I’m using proc_open in php to launch a subprocess and send data back and forth.
At some point I’d like to wait for the process to end and retrieve the exit code.
The problem is that if the process has already finished, my call to proc_close returns -1. There is apparently much confusion over what proc_close does actually return and I haven’t found a way to reliably determine the exit code of a process opened with proc_open.
I’ve tried using proc_get_status, but it seems to also return -1 when the process has already exited.
Update
I can’t get proc_get_status to ever give me a valid exit code, no matter how or when it is called. Is it broken completely?.
My understanding is that
proc_closewill never give you a legit exit code.You can only grab the legit exit code the first time you run
proc_get_statusafter the process has ended. Here’s a process class that I stole off the php.net user contributed notes. The answer to your question is in the is_running() method:Hope this helps.