-1
I have a script that imports the properties of a real estate by an xml.
When there are many properties, it gives timeout after 30 seconds (Maximum Execution time of 30 Seconds exceeded).
Is there any way around this? Below my shorthand code and an alternative that I tried but failed.
$xml = simplexml_load_file("/arquivo.xml");
foreach($xml->children()->children() as $i){
//PEGA OS DADDOS DO XML
//PEGA FOTOS E REDIMENSIONA
//INSERE NO BANCO DE DADOS
}
Then I tried to get him to upgrade from one to one, updating the page.
He first inserts all the properties into a database called "IMPORT". Then take the last one, pull the data imports and deletes from that bank, and so on until you finish.
//FAZ CONSULTA MYSQL BUSCA QUAIS IMOVEIS PARA IMPORTAR PEGANDO APENAS O ULTIMO
$xml = simplexml_load_file("/arquivo.xml");
foreach($xml->children()->children() as $i){
if($i->id_xml==$id_consulta){
//PEGA OS DADDOS DO XML
//PEGA FOTOS E REDIMENSIONA
//INSERE NO BANCO DE DADOS
//EXCLUI ESSE IMÓVEL DO BANCO DE DADOS "IMPORTAR"
}
}
That way he stayed longer, but after a while he also hangs.
Take a look https://www.php.net/manual/en/function.set-time-limit.php
– Augusto Vasques
What takes the most time on the tasks you are performing? Have you tried to evaluate which part it takes the most to isolate it? My guess is to download and resize the images. You can take an out-of-flow approach to running this process through a queue or messaging.
– gmsantos
Well, I understand that you update the page every time you enter it. Correct? If so, I recommend block insertion. How’s your script’s rule for Insert?
– Angelo Reis
<code>
protected function inserir(array $ins):
 {
 try {
 $col = implode(", ", array_keys($ins));
 $val = ":" . implode(", :", array_keys($ins));
 $stmt = Connect::getInstance()->prepare("INSERT INTO {$this->entity} ({$col}) VALUES ({$val})");
 $stmt->execute($this->filter($ins));
 return Connect::getInstance()->lastInsertId();
 } catch (\PDOException $exception) {
 $this->fail = $exception;
 return null;
 }
 }
</code>
– Angelo Reis