Je pose ma question ici car vous aviez répondu à une question similaire il y a quelques années car le cas de quelqu'un qui souhaitait savoir comment augmenter la mémoire allouée à son script.
En réalité, moi je cherche plutôt dans un premier temps à réduire la taille de mon script.
Un script qui extrait des infos d'une table mysql pour le sortir en xml. Il y a environ 60000 entrées dans la table. Le script bloque à 21000.
Je ne vois pas comment réduire les ressources qu'utilise mon script, si vous avez la moindre idée, je vous écoute.
Voici le code
Code : Tout sélectionner
<?php
function xmlentities($text){
$search = array('&','<','>','"','\'');
$replace = array('&','<','>','"',''');
$text = str_replace($search,$replace,$text);
return $text;
}
/* On génère le flux */
set_time_limit(0);
$nb_page = 0;
$date = date("Y-m-d");
$base = "https://www.monsite.fr/";
//Entete XML;
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"."\n";
$xml.= "<Mitula>"."\n";
//Recherche de tous les biens en vente
$sql = "SELECT [MES COLONNES]
FROM [MA TABLE 1 ] as a
INNER JOIN [MA TABLE 2 ] AS m ON [COL] = [COL]
INNER JOIN [MA TABLE 3 ] AS d ON [COL] = [COL]
INNER JOIN [MA TABLE 4 ] AS c ON [COL] = [COL]
WHERE [COL] = 1 and [COL] >= '".$date."' or [COL] = '0000-00-00'
ORDER BY [COL] DESC , [COL] DESC";
$result = $pdo->query($sql)->fetchAll();
foreach($result as $row){
$lienBien = rewriteUrl('annonce', $row['[COL] '], $pdo);
$id=$row['[COL] '] ;
$title=$row['[COL] '] ;
$idtype=$row['[COL] '] ;
if ($idtype == 1 or $idtype == 2 or $idtype == 3) { $type = "Sale" ; } else
if ($idtype == 5) { $type = "SALE" ; } else { $type = "PG" ; }
$content=$row['[COL] '] ;
if ($idtype == 1) { $property_type = "A" ; } else
if ($idtype == 2) { $property_type = "M" ; } else
if ($idtype == 3) { $property_type = "I" ; } else
if ($idtype == 5) { $property_type = "LC" ; } else
if ($idtype == 6) { $property_type = "PG" ; } else { $property_type = "" ; }
$floor_area=$row['[COL] '] ;
$city = $row['[COL] '] ;
$long = $row['[COL] '] ;
$lat = $row['[COL] '] ;
$region = $row['[COL] '] ;
$city_area=$row['[COL] '] ;
$idrooms = $row['[COL] '] ;
if ($idrooms == 1) { $rooms = 1 ; } else
if ($idrooms == 2 or $idrooms == 21) { $rooms = 2 ; } else
if ($idrooms == 3 or $idrooms == 22) { $rooms = 3 ; } else
if ($idrooms == 4 or $idrooms == 23) { $rooms = 4 ; } else
if ($idrooms == 5 or $idrooms == 24) { $rooms = 5 ; } else
if ($idrooms == 25) { $rooms = 6 ; } else { $rooms = "" ; }
$price=$row['[COL] '] ;
$postcode=$row['[COL] '] ;
$address=$row['[COL] '] ;
//$picture_url=$row['[COL] '] ;
$parking=$row['[COL] '] ;
$virtual_tour=$row['[COL] '] ;
$date=$row['[COL] '] ;
$plot_area=$row['[COL] '] ;
if ($row['[COL] '] == 1) {$is_furnished=1;} else {$is_furnished=0;}
if ($row['[COL] '] > '2012-01-01') {$is_new=1;} else {$is_new=0;}
//$condition=$row['[COL] '] ;
if ($row['[COL] '] != '0000-00-00') {$year=substr($row['[COL] '], 0, -6) ;}
$agency = $row['[COL] '] ;
if ($row['[COL] '] == 1) {$by_owner = 1;}
if ($row['[COL] '] > 0) {
$rnz = $row['[COL] '] ;
$note = "Note" ;
} else {
$rnz = "" ;
$est = "" ;
}
$tabPhoto = photoAnnonce($pdo,$row['[COL]']);
$xml.= "<ad>"."\n";
$xml.= "<id><![CDATA[".$id."]]></id>"."\n";
$xml.= "<url><![CDATA[".$base.xmlentities($lienBien)."]]></url>"."\n";
$xml.= "<title><![CDATA[".$title."]]></title>"."\n";
$xml.= "<type><![CDATA[".$type."]]></type>"."\n";
$xml.= "<content><![CDATA[".$rnz.$content.$note."]]></content>"."\n";
$xml.= "<property_type><![CDATA[".$property_type."]]></property_type>"."\n";
$xml.= "<floor_area><![CDATA[".$floor_area."]]></floor_area>"."\n";
$xml.= "<city><![CDATA[".$city."]]></city>"."\n";
$xml.= "<city_area><![CDATA[".$city_area."]]></city_area>"."\n";
$xml.= "<region><![CDATA[".$region."]]></region>"."\n";
$xml.= "<rooms><![CDATA[".$rooms."]]></rooms>"."\n";
$xml.= "<latitude><![CDATA[".$lat."]]></latitude>"."\n";
$xml.= "<longitude><![CDATA[".$long."]]></longitude>"."\n";
$xml.= "<price><![CDATA[".$price."]]></price>"."\n";
$xml.= "<postcode><![CDATA[".$postcode."]]></postcode>"."\n";
$xml.= "<address><![CDATA[".$address."]]></address>"."\n";
$xml.= "<pictures>"."\n";
foreach($tabPhoto as $unePhoto){
if($row['[COL] '] == 1) {$idpic = $unePhoto['[COL] '] ; } else
if($row['[COL] ']>"44692" && $row['[COL] '] != 1) {$idpic = $unePhoto['[COL] '] ; }
else {$idpic = $unePhoto['[COL] '];}
$pic = "imagesClients/".$idpic ;
$xml.= "<picture>"."\n";
$xml.= "<picture_url><![CDATA[https://www.monsite.fr/".$pic."]]></picture_url>"."\n";
$xml.= "</picture>"."\n";
}
$xml.= "</pictures>"."\n";
$xml.= "<parking><![CDATA[".$parking."]]></parking>"."\n";
$xml.= "<agency><![CDATA[".$agency."]]></agency>"."\n";
$xml.= "<virtual_tour><![CDATA[".$virtual_tour."]]></virtual_tour>"."\n";
$xml.= "<date><![CDATA[".$date."]]></date>"."\n";
$xml.= "<plot_area><![CDATA[".$plot_area."]]></plot_area>"."\n";
$xml.= "<is_furnished><![CDATA[".$is_furnished."]]></is_furnished>"."\n";
$xml.= "<is_new><![CDATA[".$is_new."]]></is_new>"."\n";
//$xml.= "<condition><![CDATA[".."]]></condition>"."\n";
$xml.= "<year><![CDATA[".$year."]]></year>"."\n";
$xml.= "<by_owner><![CDATA[".$by_owner."]]></by_owner>"."\n";
$xml.= "</ad>"."\n";
$nb_page++;
}
unset($sql,$result,$row);
$xml .= '</flux>';
// On écrit le nouveau contenu
$monfichier = fopen('/mon/dossier/flux.xml', 'w+');
fputs($monfichier, $xml);
fclose($monfichier);
?>