504 de error Gateway en gran consulta SQL en PHP

Kaleem Qasim:

Hola tengo un proyecto en el que estoy almacenar algunos datos de archivo XML en mi base de datos, que los datos es tan grande que se necesita algún tiempo, pocos datos se insertan como 30thousands en cuando me siento 504 de puerta de enlace de tiempo de espera. He intentado aumentar max_execution_time de php.ini, pero que no funcionó. Im usando cpanel

miscript

$xml=simplexml_load_file($url) or die("Error: Cannot create object");
        $totalproducts = $xml->shop->offers->offer->count();
        for($x=0 ; $x < $totalproducts; $x++){
            if(!empty($xml->shop->offers->offer[$x])){
                $name = $xml->shop->offers->offer[$x]->name;
                $price = $xml->shop->offers->offer[$x]->price;
                $description = $xml->shop->offers->offer[$x]->description;
                // $description = preg_replace('#[^a-zA-Z0-9 ]#', "", $description);
                $description = str_replace('"', "", $description);
                $description = str_replace("'", "", $description);
                // $description = mysqli_real_escape_string($description);
                $imglink = $xml->shop->offers->offer[$x]->picture;
                $url = $xml->shop->offers->offer[$x]->url;
                $catname = 'shoes';
                $program = $_POST['programname'];
                $sql = "INSERT into products(categoryname,productname,productdiscription,price,url,program,image) VALUES('$catname','$name','$description','$price','$url','$program', '$imglink')";
                if ($conn->query($sql) === TRUE) {
                    // echo "New record created successfully";
                } else {
                    // echo "Error: " . $sql . "<br>" . $conn->error;
                }
            }
        }
Farzan Takhsha:

Creo que el problema viene de "simplexml_load_file ()" función. Probablemente cargar XML lleva mucho tiempo. Si está seguro acerca de la función, que agrega una línea de código pocos para evitar tiempo de espera, pero no disminuir el tiempo de:

<?php
if (isset($_GET['offset'])){$offset=$_GET['offset'];}
else {$offset=0;}

$xml=simplexml_load_file($url) or die("Error: Cannot create object");
        $totalproducts = $xml->shop->offers->offer->count();
        for($x=$offset ; ($x < $totalproducts && ($x < (($offset+1)*100)); $x++){
            if(!empty($xml->shop->offers->offer[$x])){
                $name = $xml->shop->offers->offer[$x]->name;
                $price = $xml->shop->offers->offer[$x]->price;
                $description = $xml->shop->offers->offer[$x]->description;
                // $description = preg_replace('#[^a-zA-Z0-9 ]#', "", $description);
                $description = str_replace('"', "", $description);
                $description = str_replace("'", "", $description);
                // $description = mysqli_real_escape_string($description);
                $imglink = $xml->shop->offers->offer[$x]->picture;
                $url = $xml->shop->offers->offer[$x]->url;
                $catname = 'shoes';
                $program = $_POST['programname'];
                $sql = "INSERT into products(categoryname,productname,productdiscription,price,url,program,image) VALUES('$catname','$name','$description','$price','$url','$program', '$imglink')";
                if ($conn->query($sql) === TRUE) {
                    // echo "New record created successfully";
                } else {
                    // echo "Error: " . $sql . "<br>" . $conn->error;
                }
            }
        }
Header("Location: yourpage.php?offset=".($offset+100));
echo ($offset+100).' items inserted';
?>

Esto divide la inserción de 100 elementos por 100 artículos. puede cambiar de 100 a más artículos en cada momento.

Supongo que te gusta

Origin http://43.154.161.224:23101/article/api/json?id=343204&siteId=1
Recomendado
Clasificación