I have an exe file which has the following code:
while(1)
printf("hello\n");
I’m executing this exe through php using shell_exec
$output = shell_exec(‘C:/Users/thekosmix/Desktop/hello.exe 2>&1’);
echo $output;
now the script is executing for very long time untill i kill the process from task manager and it gives fatal error:
(Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 133693440 bytes) in C:\xampp\htdocs\shell\index.php on line 7)
I want the script (or this function) to run for a given time duration and print whatever output is generated during the time-duration not any fatal error. set_time_limit() is also not solving the problem.
You can’t do this from within PHP –
set_time_limit()is only checked after each PHP statement gets executed. Under linux you’d useulimit, but it looks like you’re using Windows.You’ll need to either modify the
hello.exeexecutable to build in a timeout, or write a wrapper that you call from PHP, which callhello.exeand handles the timeout. In any language that can easily fork, this is trivial.