Optimisation requête cron
Bonjour,
J'ai actuellement ce script cron qui charge les données de 33 mondes ...
Le problème étant qu'il est long ... et je voudrais savoir comment faire pour l'optimiser ! Merci d'avance :)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| <?php
include("XXX");
$sql = "SELECT * FROM infos" ;
$fichiers = array();
$res = mysql_query($sql);
while ($data = mysql_fetch_object($res))
$fichiers[] = $data->name;
$fichiers2[] = $data->numero;
function uncompressp($srcName, $dstName) {
$string = implode("", gzfile($srcName));
$fp = fopen($dstName, "w");
fwrite($fp, $string, strlen($string));
fclose($fp);
}
foreach($fichiers as $V)
{
$sql = mysql_query("SELECT * FROM infos WHERE name='".$V."'") or die('Erreur SQL !'.$sql.'<br>'.mysql_error());
while($data2 = mysql_fetch_array($sql)) {
$file = "http://".$data2['numero'].".grepolis.com/data/players.txt.gz";
}
$newfile = "../mondes/".$V."/data/players.txt.gz";
$path_end = "../mondes/".$V."/data/players.txt";
copy($file, $newfile);
uncompressp($newfile,$path_end);
unlink($newfile);
mysql_query("TRUNCATE TABLE ".$V."_players");
$sql = mysql_query("LOAD DATA LOCAL INFILE '$path_end' INTO TABLE ".$V."_players FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' ESCAPED BY '\\\\' LINES TERMINATED BY '\n'") or die('Erreur : '.mysql_error());
}
?> |