I\'m looking for a way to run a PHP process with a timeout. Currently I\'m simply using exec(), but it does not provide a timeout option.
What I also tried is openin
I am facing the same problem that I have tried all the answers above, but windows server cant work with any of these, maybe it is my stupidity.
My final working solution for windows is executing a batch file,
timeout.bat
::param 1 is timeout seconds, param 2 is executable
echo "running %2 with timeout %1"
start %2
set time=0
:check
tasklist /FI "IMAGENAME eq %2" 2>NUL | find /I /N "%2">NUL
::time limit exceed
if "%time%"=="%1" goto kill
::program is running
if "%ERRORLEVEL%"=="0" ( ping 127.0.0.1 -n 2 >nul & set /a time=%time%+1 & goto check) else ( goto end)
:kill
echo "terminate"
taskkill /im %2 /f
:end
echo "end"
the php command
exec("timeout.bat {$time} your_program.exe");