1

I want to run a script daily that will Select data from a database, loop through the results and execute another script for each row of results. The second script will then run more queries and create XML files from the data. Sometimes is can be a large amount of data.

//RUN SCRIPT DAILY TO GET ALL CATEGORY AND PRODUCT XML FOR STORES
set_time_limit(0);    
$select= "SELECT * FROM bookstores" ; 
$run = mysql_query($select);
while($row = mysql_fetch_array($run)){
    //run 2nd script here but how?
}

I have two questions:

1) What is the best way to execute the 2nd script in the while loop? Will the 2nd script for the first row have to be completed before the 2nd row sets the script running again or will they all run similtaeously?

2) When I run the 2nd script, it works for most unless there are too many results, in which case i get the below error:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 71 bytes) in /var/www/web/classes/class.Products.inc.php on line 90

Will this stop script 1 from running or will it move onto the next row and re-execute the script? Note I have used set_time_limit() function in both scripts.

Many thanks in advance for any help and advice on how to best achieve this without it crashing!

1
  • Just a thought, but perhaps if you include your second script's code as well people might be able to help by pointing out any optimizations, if at all possible.
    – Lucas
    Nov 10, 2011 at 13:42

1 Answer 1

1

If you are getting memory size error then use the following.

ini_set("memory_limit","256M"); 

// You can increase memory limit based on your server RAM Size.

Suggestion:

  1. Use select query with limits. For Eg. For every 1000 or 5000 limit, use sleep command.

I hope so, the above will help you.

3
  • thanks but I really need to get all of the results, is there no other way of doing this other than increasing the memory limit? Its alreay at 500mb. Can anyone help with the 1st point? I still dont know how to execute the 2nd script properly...
    – LeeTee
    Nov 10, 2011 at 17:43
  • if you can't able to increase the memory limit, then fetch the record of bookstores and save it as CSV format. Then use the CSV file to run 2nd second script.
    – Raja
    Nov 11, 2011 at 5:00
  • Ok thanks, but still how do I run the 2nd script from the 1st? Do I use cURL or something?
    – LeeTee
    Nov 11, 2011 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.