I wrote the parser, which parses the yandex YML with the goods, as well as copies all the pictures of the goods and puts everything into the database, disassembles the pictures into folders. The file in which 400 goods parsit is normal, but the file with 27411 goods passes for a very long time. In the settings, how many goods are set to parse at a time, set a different number, no sense. For each pass, the parser is loaded again.

$yml = simplexml_load_file($shop_info["yml_location"]); 

Is it possible to somehow receive goods of 10 or 20 pieces from a file? That would not constantly load the entire file. Hosting can not stand. But on Denver loads everything clearly quickly.

  • You have a typo somewhere. In the topic it is written that the xml in the question is parsed - yml. It is not clear what exactly you are working with. - Arnial
  • one
    Your parser is a dom parser. In any case, it loads everything into memory and then builds a tree. And this usually requires two to three times the amount of memory (compared to the original file). You need to take a sax parser - it loads a bit and passes the file in one pass. Yes, its use is a bit more complicated, but the result may please. - KoVadim
  • Question to google google.com/... The first answer for an example is dpyatkov.ru/2012/01/12/simplexmlreader - Visman
  • @Arnial xml = yml = the same thing. KoVadim also read about sax, but it may still be an option to finish it all, all the same there is a lot of code in it, I don’t want to spend the day again. - Vladimir
  • one
    First you need to state the problem not in the terminology of a housewife, but by giving specific numbers and error messages. What is "very slow"? What exactly is the "hosting does not stand"? What errors does the script produce? - Ipatiev

1 answer 1

The XMLReader library is best suited for parsing large XML files using PHP.

The library supports the processing of compressed XML files.

 $xmlfile = 'compress.zlib://dir/largefile.xml.gz'; $reader = new XMLReader(); $reader->open($xmlfile);