View Full Version : export cron job?

09-01-2006, 11:11 AM

we have various massive exports which are run on our application - they generally take a couple of minutes to produce an XLS file (its financial data).. the trouble is, now the people above have asked for more detailed reports, which is now resulting in the files taking upto 5 minutes to be produced, and in IE the browser is just timing out. (seems ok in FF)

I was using the web control panel and the backup on that seems to say "the backup has been placed in a queue. you will receive a notification once complete". How can I do a similar thing?

does it create a CRON job for that request or something? I cannot think of another way to call the export PHP script in the background and get it to run without the user seeing it.

any ideas?!

ive wondered about having a single CRON job say "fetch_requests.php" which is called every 2 minutes. Then if someone requests an export, it will add their request to the database. The CRON script will check the database for any requests, and perform the export based on the values stored in the DB. Is there any implications on the server if it's checking the DB every 2 minutes?!

09-01-2006, 07:59 PM
when they request the 'build' start the job via AJAX and for the timeout problem do a rolling report.

timeBox the job to say, 60 seconds. after 60 seconds call a 'submit, load, and continue' method.

hrmm, how can i better explain this.

say it is 10 000 xml nodes.

after writing the first 1000, save the file as is, then run the process again starting where you left off.

while this is all happening you shouldn't reveive a timeout on the page (because your using ajax), and the users can visually see the process.

maybe add a little 'generating' box and each itteration of the script increment the percentage?

i would go with the Cron Job solution last. as it is very strenous on the server and would possibly kill your bandwidth.

also, if my solution does not fit you can look into hidden frames containing the php code, execute from there and make callbacks to the parent via javascript.

Hope this helps.

09-04-2006, 09:39 AM
thanks for the reply - your example seems perfect! Cant believe I never thought of doing that before! It'd be nice to show a user a percentage complete too, rather than a simply "Please wait" message.

Just out of interest, what is a timeBox?

I was thinking of doing a mysql_num_rows() query to work out the total rows for the job, then work a percentage from that?

09-05-2006, 03:07 PM
timebox is a method to not allow yourself to go over a said amount of time for a said tast. in your case you'll want to find the server timeout. and make your a bit smaller.