tags:

views:

97

answers:

2

Below is my code, it is a script I need to run just 1 time to update a new mysql table I have added, I have 60,000 users and it ran and added 268 rows, it did not show any errors or anything, it just didnt add the rest and I have no idea why?

    <?PHP
require_once "../config/functions.inc.php";

// get users
$sql = 'SELECT * FROM  friend_login';
$result = executequery($sql);   
while($row = mysql_fetch_assoc($result)){
    // get states
    $sql = 'SELECT * FROM  usstates order by rand() limit 1';
    $state = getSingleResult($sql);
    //convert to lat and long
    $geo = get_geo($state);
    $lat = $geo['Latitude'];
    $long = $geo['Longitude'];

    //insert lat/long into locations table
    $insert = "INSERT INTO friend_location (user_id, lat, `long`) VALUES ('$row[auto_id]', '$lat', '$long')";
    executeQuery($insert);

    echo 'user updated with ' .$state. ' <BR> userID=' .$row[auto_id]. ' <BR><BR><BR>';
}
?>
+3  A: 

try setting the maximum script execution time to 0 (infinite):

ini_set('max_execution_time', 0);

If you have display_errors or error_reporting turned off, then you may not see a fatal error generated by a timeout.

Tom Haigh
I just tried this, so far so good, its been running for about 5 minutes and has updates about 1k of 60k. This is gonna take a while, maybe I shouldn't have made it output to the browser, my browser will probably crash
jasondavis
That's verrrry slow but if this is just a one-off there's not any point optimizing your code
Greg
For the record though: ORDER BY RAND() is slow, doing a query every time around the loop is slow, and inserting individual rows instead of in batches is slow :)
Greg
yes it is! 30 minutes later now and it's only 1/6th done lol I never knew something like this would timeout so fast though, the timeout time must be much smaller on my home server then my production server
jasondavis
Or use the equivalent set_time_limit(0)
daremon
A: 

Umm mines set to 48

set_time_limit(48);