There is an xml file enter image description here

I wrote a parser and a script that later adds products to, but it works for a long time, and if there are more entries in the xml file, it does not have time to work to the end.

$languages = simplexml_load_file("test.xml", null, LIBXML_NOCDATA); $i = 0; foreach ($languages->groupProduct as $group) { if((string) $group['name'] == "01 Плитка") { foreach ($group->element_list->element as $element) { $data = array(); //массив данных $file_name = date('YmdHis').rand(100,1000); $data["img"] = $file_name.".jpeg"; foreach($element->minpart_list->minpart as $minpart) $data["description"] .= $minpart."<br />"; if ($this->add($data)) { $this->download_remote_file($element->pic, "../".$this->config->dir_img_products.$data["img"]); } $i++; } } } function download_remote_file($file_url, $save_to) { $content = file_get_contents($file_url); file_put_contents($save_to, $content); } 

How can I increase the performance of the script?

  • one
    as an option, increase max_execution_time in the settings of pkhp - teran

2 answers 2

Just download files through curl_multi in several streams ( example ).

  • The option is good, but is there enough channel width and memory? - E_p
  • But with my vangovaniyu bad. It is necessary to try. You will rest in love with the channel with a large number of streams (so you need to swing at night) or pick up the number of streams. From memory also need to pick up. Most likely you will hit the number of simultaneous connections to the ftp server and the lack of a channel, and even less the lack of memory just will not work. - hardworm

Yes, everything is simple, you (your provider) FTP is slow. What kills you network latency.

Read Protection from frequent requests to the page . The man had the same problem.

You have several options.

  1. Increase script time. (Neither of which will decide.)
  2. Use the work queue. (RabbitMq, ZeroMQ ...). The main script throws off work, and download background scripts.

http://www.rabbitmq.com/tutorials/tutorial-one-php.html

http://zguide.zeromq.org/php:_start