Take the 2-minute tour ×

Scenario I have an export.php file that remotely exports a 1000 images. It's broken down to export 20 images then reload and do the next 20 until all images have been exported. This works fine the thing is I wanted to make it look cleaner and have it running in the background.

So as I have jQuery on my index.php page I done a simple ajax call and HOPED the response would be "20" then "40" and so on, showing how many images have been exported so far. If only it would of been that easy.

The problem is that my front page gets updated with the first call but I need it to carry on running and updating until I say so. No doubt I am missing something simple, it's always the way.

Any help would be appreciated and I hope that makes sense.

ajax call:

   url: "export_images.php",
   cache: false,
   success: function(data){
share|improve this question
Do you have any code samples you can provide? –  Aaron Hathaway May 12 '11 at 22:31
I wonder if you're php is already reporting something at the end of each batch process. If so, and your ajax script is working, then chances are the reports are in the responseText. –  robx May 12 '11 at 22:35
I understand the problem. It's because it runs the page once and returns the result from initial load which is 20. When export_images.php reloads to process the next 20 images it takes over the whole page and starts running as if I went to the page directly. I am looking for it to carry on running in the background and update #export_images_result as it's running. Then at the end say something like "842 images have been exported". –  StevenBullen May 12 '11 at 22:46
add comment

2 Answers

up vote 1 down vote accepted

You could just call the php file every 20 images using separate ajax calls & pagination. Instead of having the php file do it. I would be happy to give an example if you post the php, and the rest of the javascript.

I would recommend not using post for such a large upload, but maybe public ftp or something. POST is so unreliable, and doesn't give progress, etc. FTP is far from perfect, but a better option (imo) for this type of system. Though I guess you don't get to choose sometimes.

share|improve this answer
It's actually scraping from a website so no POST involved. Could I wrap it in a function and make it call on it self until the success result returned "All images exported". Then just check for that in the function and add a break. –  StevenBullen May 12 '11 at 22:57
Wait, if you are screen scraping, wouldn't you only use php? –  Ben May 12 '11 at 22:59
erm... The export_images.php does the scraping I just want the front end for the user to not show the reloading of the php page. Am I missing something? –  StevenBullen May 12 '11 at 23:06
I think I see what you are doing. You have a php program scraping images off a site, and sending them to the browser through an ajax call. –  Ben May 12 '11 at 23:11
Well it sends them to a temp directory to be zipped up later on for the user to download, but same in principal. I like @jason idea below of letting the page run without a return result (sounds dangerous) and then polling my mysql database for how many have been processed out of the 1000. The export_images.php does have fall back for any problems whilst the script is running so it will try again for any images not processed, images that sometimes come back with 0 bytes, etc. –  StevenBullen May 12 '11 at 23:21
add comment

You probably want to use a jquery timer to call the page repeatedly so it can process all of the images.

share|improve this answer
I am guessing a timer would be a bad route to go as you don't know when the page has finished processing to start the next one. –  StevenBullen May 12 '11 at 22:58
so each time the page loads, another 20 images are processed? I think you could include some logic on the page that returns the number of images that have been processed, and if the 20 are finished start another batch. i think you need some sort of loop to call the page to load the next batch, but without seeing the code its tough to say. alternatively, if the single page load kicks off the batch for all 1000, you may want another page that can just return the number images that have been processed thus far, which you could poll via ajax. –  Jason May 12 '11 at 23:12
I like that idea I am going to test it out and see how it goes. I think I might try the idea above as well, of looping a function that on success does another 20 images until complete. –  StevenBullen May 12 '11 at 23:22
add comment

Your Answer


