|
Posted by Etienne Marais on 11/15/05 15:47
Another option is to stream data to the browser using
php (and javascript). Set the timout directive high enough
(I think the default is 30 seconds for execution of one
script). Then, using PHP, monitor the progress and send
update information after each loop (for instance) to the
browser:
while ($longtask!="DONE") {
while($process_subtask) {
// time consuming processing (per item)
}
// Fill output buffer to at very least 255 characters
// Experiment for browser specific needs.
echo "<!-- ".(str_repeat("*",255))." -->";
// Report Back
echo "<br> Task ".($i++)." completed";
flush();
}
Using this to get started, you can then add Javascript and the DOM
for HTML to display something nice, like a progress bar or X% completed
within a table's <td>, i.e. name your <td id='progress> then stream
echo"<script>document.all.progress.firstChild.value='$percentage'</script>";
Instead of $i.
Regards
Etienne Marais
Cosmic Link
312 Kent Avenue
South Africa
Andrew wrote:
> Look into the ignore_user_abort and set_time_limit functions.
>
> Print a nice 'please wait' page and flush it to the webserver, then
> when you're done with your processing, check if the user is still
> waiting (there are functions for that too, read the manual) and flush a
> "done" message.
>
> Another alternative would be to trigger some external (seperate to the
> webserver) program or script to do the work, like a perl script, and
> run it into the background from PHP.
>
> Remember, most users won't wait more than 20 seconds, so consider
> alternative pre-processing and caching strategies if they are feasible.
[Back to original message]
|