user813720
user813720

Reputation: 451

automating a script in several stages or several times

I need to run a script every night that connects to a Web Service via SOAP with a maximum return of 45000 records.

I can set how many records to return and it seems that the limit is 1000 before I hit the max_execution_time limit.

What would be the best way to automate this script to get all 45000 records? Surely there is a better way than to do 45 cron jobs?

Upvotes: 0

Views: 40

Answers (2)

Jordan Mack
Jordan Mack

Reputation: 8733

If you want this to run automatically every night, a single cron job is definitely the way to go. There are two basic approaches you could take on this: You could either run a single job that does query after query, pulling x number of records each time, until it pulls all the records, or you could have one that runs over and over again every few minutes, and pulls x numbers of records each time. Both have strengths and drawbacks, but the first option is probably the easier to implement.

To do this, I would recommend that you raise the time limit using set_time_limit(). This should be something very high so that your process will have time to complete, or simply 0 if you have no limit. If you have memory issues as well, then I would pull much less each time. If you say the max is 1000, then consider 500. Have your application loop over and over pulling 500 records at a time until it completes. You may also want to throw in a small delay between each record pull using sleep().

Upvotes: 1

Damp
Damp

Reputation: 3348

This should help http://php.net/manual/en/function.set-time-limit.php

Upvotes: 0

Related Questions