I have this cron job running 4 times a day which basically fetches the contents of an XML file and converts it into an Array with tags as keys. Then, the array values are entered into a database. However, I need to get several XML files, in fact, one for each user existing in my database. And I have to update the database once per user, in the same cron tab.
My code:
Code: Select all
<?php
$result = mysql_query("SELECT id FROM table1"); //getting the ID from the user
while($row = mysql_fetch_array($result)){
$contents = file_get_contents("http://www.websitexml.com/feeds/".$row['id']);
$data = XMLtoArray($contents);
mysql_query("UPDATE table1 SET column3='$data[tag1]', column4='$data[tag2]' WHERE id=$row[id]") or die(mysql_error());
}
?>
If I had to update 500 users right now, I'd probably split the number of users to be updated to about 100, then another script that continues where the last script ended. Honestly I'm not sure how to do that but for now it's not important, the most important thing right now is to know if I'm doing it correctly or if there's a better/faster way.