views:

33

answers:

1

So I just created a script to resize a whole bunch of images. Is there anyway to have there be output as its running through the loop?

Basically I have like 400 photos in photo db table. Its gathering a list of all these photos, then looping through each one and resizing it 3 times. (large,medium,small version).

Right now on each loop I am echoing that images results, but I dont see the results untill EVERYTHING is done. So like 10 minutes later, I will get output. I added this set_time_limit(0); to make sure it doesnt time out.

*EDIT * It looks like every so often the script actually updates to the browser, maybe every 30 seconds?

+4  A: 

You can use flush() or ob_flush() to tell the script to send something back to the client after you do an echo().

BUT - you never really have complete control over it, the web server does, so the web server may not cooperate depending on how its configured. For example, if you have the server doing gzip rather than using PHP's gzip features, the web server may still buffer the output.

GrandmasterB
The server is sitting in my room since im workin on it as a dev server. Thanks for that info, ill give that a shit. I am using native php to resize.
Roeland
So that didnt seem to work. I am using the ImageCopyResampled() function. This is the one taking most of the processing. Any other ideas?
Roeland
Unfortunately, like I said, you dont necessarily have total control over when the web server sends the output back. One other thing you could try doing is to output larger bits of text so that whatever buffering is going on in the web server gets filled up quicker, and is sent more frequently. So instead of just echoing "Image 1<br>" after every image gets processed, echo something like "Image 1<br><!-- this is a very, very.....very long comment !>".
GrandmasterB
Alternatively, if this is a must-have feature, you might need to redesign the interface into something more 'ajaxy', perhaps making individual calls for individual images.
GrandmasterB
I see what your saying grandmaster.. that makes sense. Using a looping at the client for each image and send a php request to resize that one image and then update and iterate through next. Makes sense!
Roeland