Sid Sid - 8 months ago 46
PHP Question

PHP script stuck on exec even after running command in backgroud on Windows

I want a php script from which I can execute a program, and terminate it if it doesn't complete execution in 2 seconds. I am using Windows. I have tried the following code:

exec("start /B program.exe");
exec('taskkill /F /IM "program.exe"');

This doesn't seem to work as script is stuck on the first
statement as long as
is not finished execution. I can't figure out how to do fix this issue.


Are you doing this with php cli (command line)? Open a command prompt as administrator.
To not being blocked by waiting for the program close the process of opening the program.

php myscript.php

pclose(popen("start /B program.exe", "r"));
exec('taskkill /F /IM program.exe');

Would also be fine to put the exec start into a separate script and fire this script using exec