Forum Moderators: coopster

Message Too Old, No Replies

How to work with very intensive PHP scripts

need help coping with very processor heavy script

         

hughie

4:28 pm on May 30, 2006 (gmt 0)

10+ Year Member



I have written a very intensive script that goes through a directory and makes 5 different sizes of all the images in there.

Obviously this takes a while and as soon as there are more than a few images this script will run for 30 seconds +

What i would like to do is let the script run for as long as it takes without melting the server, whilst keeping a report on how long to go, out to the browser.

What i normally do is let a script like this do a few operations, then let it end, outputting a meta-refresh to the browser, then continuing where it left off once the page reloads.

Is it possible to do it another way?

FalseDawn

5:07 pm on May 30, 2006 (gmt 0)

10+ Year Member



You don't really need to let the script end. I imagine that you can use the "sleep" command to possibly lower the cpu load - maybe 1/10 sec between every image for example.

As far as a progress meter - you could just count the number of images in the directory, then after each one, output something like "processed m of n images" to the browser.

For long scripts, you also need to use set_time_limit(0);

hughie

12:55 pm on May 31, 2006 (gmt 0)

10+ Year Member



Many thanks FalseDawn

use of the set_time_limit(0) and the sleep command seems to work nicely.

what wasn't happening was the ouputting to browser, it's a bit hit n miss on my local Win32 Apache but seems fine on my server using flush(), end_flush() so long as i send a decent amount of html to the browser first (php suggest I.E. likes at least 256 bytes before any output gets sent).

thanks again
hughie