When I run an exec
from PHP like so:
$result = exec('command');
The results from this will be stored in $result
. But in my current case, my command can take a few minutes and outputs results as it is running. Is there a way I can get output while it is running? I know that the passthru
method will output the results to be browser, but I actually want it directly.
You should take a look at proc_open
After making the output stream non-blocking (with stream_set_blocking
), you can read from it whenever you want without having your PHP-code blocked.
-Edit- If you use
$result = exec('command > /path/to/file &');
It will run in the background and you can read the output in /path/to/file
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