I’m trying to execute a command (in both Windows and Linux) via PHP. My target is to have multiple instances of the command running at the same time (hence background) but I need to grab the output of each also.
This doesn’t work as the output cannot be grabbed.
function execInBackground($cmd) {
if (substr(php_uname(), 0, 7) == "Windows"){
pclose(popen("start /B ". $cmd, "r"));
}
else {
exec($cmd . " > /dev/null &");
}
}
Will forking help me? I saw PHP exec in background using & is not working too but again where to get the output?
Any ideas would be great!
EDIT: We are using PHP v5.2, other PHP versions cannot be used!
Exec the command with & and output to a file:
After that you can read contents when its done.
Try this for executing a PHP script AFTER the first command was ended, using the ; between instructions.