DeletedUser
Guest
Hey all,
I'm trying to develop some tools for my alliance (if it works out well, and I get real hosting, I'll make it public), and my first step was to download some town data. I used the example I found, but kept getting errors with execution time, so I incrementally increased it with ini_set(). I tried 5 minutes, 10 minutes, 20 minutes, but at 30 minutes it finally finishes and the data is there.
Can anyone tell me if there is an easier way to do it, that will take less time? I was wanting to update hourly, but if its going to take 30 minutes to execute, it would seem more logical to do it ever 2-4 hours. Can anyone give me a pointer towards updating a DB more quickly?
I'm trying to develop some tools for my alliance (if it works out well, and I get real hosting, I'll make it public), and my first step was to download some town data. I used the example I found, but kept getting errors with execution time, so I incrementally increased it with ini_set(). I tried 5 minutes, 10 minutes, 20 minutes, but at 30 minutes it finally finishes and the data is there.
Can anyone tell me if there is an easier way to do it, that will take less time? I was wanting to update hourly, but if its going to take 30 minutes to execute, it would seem more logical to do it ever 2-4 hours. Can anyone give me a pointer towards updating a DB more quickly?
Code:
$dbh = mysql_connect ("localhost", "grepo_claims",
"fakepass") or die('Cannot connect to the database because: ' . mysql_error());
mysql_select_db ("grepo_claims");
ini_set("memory_limit","100M");
ini_set('max_execution_time', 1800);
mysql_query("Truncate Table towns");
$datafile = gzfile('http://en30.grepolis.com/data/towns.txt.gz');
if(!is_array($datafile)) die("File could not be opened");
foreach($datafile as $datum){
list($id, $player_id, $name, $island_x, $island_y, $number_on_island, $points) = explode(',', $datum);
If (!isset($id)){ $id=0; }
If (!isset($player_id)){ $player_id=0; }
If (!isset($name)){ $name=0; }
If (!isset($points)){ $points=0; }
$INSERT = "INSERT INTO `towns` (`id`, `player_id`, `name`, `island_x`, `island_y`, `number_on_island`, `points`) VALUES ('$id', '$player_id', '$name', '$island_x', '$island_y', '$number_on_island', '$points')";
$result = mysql_query("$INSERT");
if (!$result) {
print"$id, $player_id, $name, $island_x, $island_y, $number_on_island, $points <br>";
print"$INSERT <br>";
die('Invalid query: ' . mysql_error());
}
}
print "DB Updated Successfully";
mysql_close($dbh);