Web Hosting Talk







View Full Version : Real-time progress showing, without java


El-Vino
11-14-2006, 04:54 AM
Hi everyone...

I have a maintenance and cache generating php script that take quite a while to complete and I got to wishing it would show where it stands on a real time basis. It already output progress log like "generation of these pages .... Done" kinda line. Problem is with PHP, you get to wait until the page (and so, the script) is complete before showing anything... so you get the whole report, but only at the end.

I did some thinking and thought that I could make the script into a shell script to be executed in the background, called with shell_exec(), outputing a text file and on the web, creating a page that refreshes every second and that would load that text file, effectively showing where the maintenance stands... but that seems like overkill to do it like this, right ?

Is there a better way to do this ? a easy way ? anyone, any insight ?

keep in mind I cannot have it use any client-side technology like JAVA.

Thanks all!

anlene
11-14-2006, 05:18 AM
shhh, for you only...

http://www.php.net/ob_start
http://www.devshed.com/c/a/PHP/Output-Buffering-With-PHP/

BeZazz
11-14-2006, 06:13 AM
you may find this helpfull also
http://www.phpclasses.org/browse/package/1554.html

El-Vino
11-17-2006, 09:58 AM
Actually, anlene, the result i'm trying to achieve is more or less the opposite of that... I don't want to buffer the result until the end an send at that point (or not) but rather, I want the script progress to be shown like you would, say, a shell script.

Thanks anyways for the answer :)

zoid
11-17-2006, 10:09 AM
Have a look at the flush() (http://www.php.net/manual/en/function.flush.php) function.

Saeven
11-17-2006, 12:56 PM
Nothing PHP can do, can guarantee results in realtime, especially output buffering. Your best recourse is to use AJAX and setup a polling routine - ie; check status every half second and report it if it has changed.

I would recommend building a PHP proxy to the process, and using dojo.io.bind from dojotoolkit.org to get the job done.

Good luck.
Alex

arkin
11-18-2006, 03:34 AM
If you have root access on your machine you can put your php scripts in /etc/cron.daily or /etc/cron.hourly or even set up your own customized cron event.

Upon using this method make sure you define the PHP path as you would in perl, something like: #!/usr/local/php/bin

I have a Cron event that uses PHP to update all my awStats pages statically, it then reports the total running time (in seconds) and even reports the CPU usage at the time.

I can help you with this is you post further what you need.