in web applications, how do i handle processing of large amounts of data that usually cause timeouts? eg. processing a db to output a large report? i usually use PHP/Zend Framework/MySQL.
Asynchronous mechanisms of various sorts. For example, queue up the job in a job table and have an automated task in the background poll the table on a fixed schedule for newly-added jobs, process them, and somehow notify the user it has been done.
In one recent app, a document users must generate is actually requested in one page. This simply translates into the fact that a row is inserted into a job table. An event runs periodically, which performs all the SQL necessary to "compose" the document's data in a second table, and a third step is a PHP page that shows pending/completed documents. In this case, there is no real turnaround requirement, so people aren't actively notified via email or any such mechanism, but it'd be easy to layer that over it all.
There's a million ways to skin this cat...
set_time_limit ( int $seconds )
would allow you to modify the time limit for execution and you can reset it back to normal when you are done executing the scripts which would take a longer time to execute.
While the server side code is processing the data the client will need to poll the server periodically to keep their session alive. If you do not poll the server periodically eventually your HTTP session will expire and cause a timeout error.
One thing you can do is flush the output buffer, then send some javascript to update a progress bar during your processing. Here's an example:
<html>
<body>
<div id="progressBar" style="width: 0px; height: 20px; background: #900; color: #fff;">Progress</div>
</body>
</html>
<?
while(@ob_end_flush());
for ($i = 0; $i < 10; $i++) {
echo "<script type=\"text/javascript\">var pb = document.getElementById('progressBar'); pb.style.width = '" . ($i * 20) . "px';</script>";
sleep(1);
}
?>
I'd typically execute the task asynchronously - I think you can use something like this in PHP:
exec ("/usr/local/bin/php build_report.php")