Page is a not externally linkable
- Code, Content, and Presentation
-- PHP Server Side Scripting
---- How do I stop my PHP script from eating the processor?


rocknbil - 4:25 pm on Mar 9, 2009 (gmt 0)


Well, you could try forking the process. Part of the problem in a large or lengthy process is it has to maintain a connection with the browser.

So if you could initiate the process, then return an immediate response to the browser, the child process would continue in the background. You'd need another tool to check the progress of the child. $pid=process ID.

## First you submit and return an immediate
## response. Do not exit after the response.
&html('Checking the data');
## This is the parent, which just marks the progress
if ($pid = fork) {
&mark_progress($pid,'current_process');
}
## This is the child. You want to close STDOUT so the
## call to your HTML sub above doesn't "hang."
else {
close (STDOUT);
&do_your_large_process();
}
## So the parent doesn't kill the child
waitpid($pid,0);

The previous is a perl approach (close(),waitpid()) but it would be very easy to emulate this in PHP.


Thread source:: http://www.webmasterworld.com/php/3866254.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com