I am trying to use PHP to execute a C++ object code which has been already compiled. When the run-time of the object code if low, the PHP page loads perfectly. But when the object code takes a long time to execute, the PHP page shows time out error. Now, one way to get around this error is to increase the response time, but the duration can be increased upto only a certain extent and the duration of run of the object code will change depending on the input provided to it. I want to have a webpage that loads completely and then inside that a part where I can wait till the object code execution completes. How can I do that in PHP? I have tried all variations of shell execution in PHP like shell_exec(), exec(), system() etc.
No, you can set max_execution_time to any value you want. I have had PHP scripts running well over an hour in time.
I don't understand this part completely. You want a section inside your web page that loads content generated by your object code, but you want the rest of the page to render first in case it takes a while? If that is the case, you could do something like that with AJAX and I don't know how an iframe would work.
As for executing PHP code after outputting content, that is a feature that PHP is lacking. It is unfortunate because a lot of people would like to have their scripts continue executing without making the browser wait for PHP to close the connection. With a PHP-FPM setup, you can use fastcgi_finish_request() to do this. But with a standard PHP setup there is nothing that I am aware of that works and I have seen a lot of proposed solutions over the years. I never tried this but you may already have:
If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.
See the examples that follow in the comments section.
This topic is now closed. New replies are no longer allowed.