Question

I am trying to read a pricelist and stocklist via the product code (that comes from a database table too) from xml files and puts the result into a MySQL table.

Everything is OK except the response or read time from the xml files. The PHP script, Database and the XML file are on the same server. After a look in the Apache access.log i saw that the PHP script after its started it can read (or response) very quickly. But after a while it reads only exactly 1 per minute:

[...]
1.2.3.4 - - [09/May/2013:13:11:21 +0300] "GET /feeds/stock.xml HTTP/1.0" 200 16202 "-" "-"
1.2.3.4 - - [09/May/2013:13:11:21 +0300] "GET /feeds/price.xml HTTP/1.0" 200 82143 "-" "-"
1.2.3.4 - - [09/May/2013:13:11:21 +0300] "GET /feeds/stock.xml HTTP/1.0" 200 16202 "-" "-"
1.2.3.4 - - [09/May/2013:13:11:21 +0300] "GET /feeds/price.xml HTTP/1.0" 200 82143 "-" "-"
1.2.3.4 - - [09/May/2013:13:11:21 +0300] "GET /feeds/stock.xml HTTP/1.0" 200 16202 "-" "-"
1.2.3.4 - - [09/May/2013:13:11:21 +0300] "GET /feeds/price.xml HTTP/1.0" 200 82143 "-" "-"
1.2.3.4 - - [09/May/2013:13:11:21 +0300] "GET /feeds/stock.xml HTTP/1.0" 200 16202 "-" "-"
1.2.3.4 - - [09/May/2013:13:11:21 +0300] "GET /feeds/price.xml HTTP/1.0" 200 82143 "-" "-"
1.2.3.4 - - [09/May/2013:13:11:21 +0300] "GET /feeds/stock.xml HTTP/1.0" 200 16202 "-" "-"
1.2.3.4 - - [09/May/2013:13:11:21 +0300] "GET /feeds/price.xml HTTP/1.0" 200 82143 "-" "-"
1.2.3.4 - - [09/May/2013:13:11:21 +0300] "GET /feeds/stock.xml HTTP/1.0" 200 16202 "-" "-"
1.2.3.4 - - [09/May/2013:13:11:21 +0300] "GET /feeds/price.xml HTTP/1.0" 200 82143 "-" "-"
1.2.3.4 - - [09/May/2013:13:11:21 +0300] "GET /feeds/stock.xml HTTP/1.0" 200 16202 "-" "-"
1.2.3.4 - - [09/May/2013:13:11:21 +0300] "GET /feeds/price.xml HTTP/1.0" 200 82143 "-" "-"
1.2.3.4 - - [09/May/2013:13:11:21 +0300] "GET /feeds/stock.xml HTTP/1.0" 200 16202 "-" "-"
1.2.3.4 - - [09/May/2013:13:11:21 +0300] "GET /feeds/price.xml HTTP/1.0" 200 82143 "-" "-"
1.2.3.4 - - [09/May/2013:13:11:21 +0300] "GET /feeds/stock.xml HTTP/1.0" 200 16202 "-" "-"
1.2.3.4 - - [09/May/2013:13:11:21 +0300] "GET /feeds/price.xml HTTP/1.0" 200 82143 "-" "-"
1.2.3.4 - - [09/May/2013:13:11:21 +0300] "GET /feeds/stock.xml HTTP/1.0" 200 16202 "-" "-"
1.2.3.4 - - [09/May/2013:13:11:21 +0300] "GET /feeds/price.xml HTTP/1.0" 200 82143 "-" "-"
1.2.3.4 - - [09/May/2013:13:11:21 +0300] "GET /feeds/stock.xml HTTP/1.0" 200 16202 "-" "-"
1.2.3.4 - - [09/May/2013:13:11:21 +0300] "GET /feeds/price.xml HTTP/1.0" 200 82143 "-" "-"
1.2.3.4 - - [09/May/2013:13:11:21 +0300] "GET /feeds/stock.xml HTTP/1.0" 200 16202 "-" "-"
1.2.3.4 - - [09/May/2013:13:11:21 +0300] "GET /feeds/price.xml HTTP/1.0" 200 82143 "-" "-"
1.2.3.4 - - [09/May/2013:13:11:21 +0300] "GET /feeds/stock.xml HTTP/1.0" 200 16202 "-" "-"
1.2.3.4 - - [09/May/2013:13:11:21 +0300] "GET /feeds/price.xml HTTP/1.0" 200 82143 "-" "-"
1.2.3.4 - - [09/May/2013:13:11:21 +0300] "GET /feeds/stock.xml HTTP/1.0" 200 16202 "-" "-"
1.2.3.4 - - [09/May/2013:13:11:21 +0300] "GET /feeds/price.xml HTTP/1.0" 200 82143 "-" "-"
1.2.3.4 - - [09/May/2013:13:11:21 +0300] "GET /feeds/stock.xml HTTP/1.0" 200 16202 "-" "-"
1.2.3.4 - - [09/May/2013:13:11:21 +0300] "GET /feeds/price.xml HTTP/1.0" 200 82143 "-" "-"
1.2.3.4 - - [09/May/2013:13:12:22 +0300] "GET /feeds/stock.xml HTTP/1.0" 200 16202 "-" "-"
1.2.3.4 - - [09/May/2013:13:13:22 +0300] "GET /feeds/price.xml HTTP/1.0" 200 82143 "-" "-"
1.2.3.4 - - [09/May/2013:13:14:22 +0300] "GET /feeds/stock.xml HTTP/1.0" 200 16202 "-" "-"
::1 - - [09/May/2013:13:15:04 +0300] "GET / HTTP/1.1" 200 1007 "-" "Mozilla/5.0 (ISPConfig monitor)"
1.2.3.4 - - [09/May/2013:13:15:22 +0300] "GET /feeds/price.xml HTTP/1.0" 200 82143 "-" "-"
1.2.3.4 - - [09/May/2013:13:16:22 +0300] "GET /feeds/stock.xml HTTP/1.0" 200 16202 "-" "-"
1.2.3.4 - - [09/May/2013:13:17:22 +0300] "GET /feeds/price.xml HTTP/1.0" 200 82143 "-" "-"
1.2.3.4 - - [09/May/2013:13:18:22 +0300] "GET /feeds/stock.xml HTTP/1.0" 200 16202 "-" "-"
1.2.3.4 - - [09/May/2013:13:19:22 +0300] "GET /feeds/price.xml HTTP/1.0" 200 82143 "-" "-"
::1 - - [09/May/2013:13:20:03 +0300] "GET / HTTP/1.1" 200 1007 "-" "Mozilla/5.0 (ISPConfig monitor)"
1.2.3.4 - - [09/May/2013:13:20:22 +0300] "GET /feeds/stock.xml HTTP/1.0" 200 16202 "-" "-"
1.2.3.4 - - [09/May/2013:13:21:22 +0300] "GET /feeds/price.xml HTTP/1.0" 200 82143 "-" "-"
1.2.3.4 - - [09/May/2013:13:22:22 +0300] "GET /feeds/stock.xml HTTP/1.0" 200 16202 "-" "-"
1.2.3.4 - - [09/May/2013:13:23:22 +0300] "GET /feeds/price.xml HTTP/1.0" 200 82143 "-" "-"
1.2.3.4 - - [09/May/2013:13:24:22 +0300] "GET /feeds/stock.xml HTTP/1.0" 200 16202 "-" "-"
::1 - - [09/May/2013:13:25:03 +0300] "GET / HTTP/1.1" 200 1007 "-" "Mozilla/5.0 (ISPConfig monitor)"
1.2.3.4 - - [09/May/2013:13:25:23 +0300] "GET /feeds/price.xml HTTP/1.0" 200 82143 "-" "-"
1.2.3.4 - - [09/May/2013:13:26:23 +0300] "GET /feeds/stock.xml HTTP/1.0" 200 16202 "-" "-"
1.2.3.4 - - [09/May/2013:13:27:23 +0300] "GET /feeds/price.xml HTTP/1.0" 200 82143 "-" "-"
1.2.3.4 - - [09/May/2013:13:28:23 +0300] "GET /feeds/stock.xml HTTP/1.0" 200 16202 "-" "-"
1.2.3.4 - - [09/May/2013:13:29:23 +0300] "GET /feeds/price.xml HTTP/1.0" 200 82143 "-" "-"
::1 - - [09/May/2013:13:30:04 +0300] "GET / HTTP/1.1" 200 1007 "-" "Mozilla/5.0 (ISPConfig monitor)"
1.2.3.4 - - [09/May/2013:13:30:23 +0300] "GET /feeds/stock.xml HTTP/1.0" 200 16202 "-" "-"
1.2.3.4 - - [09/May/2013:13:31:23 +0300] "GET /feeds/price.xml HTTP/1.0" 200 82143 "-" "-"
1.2.3.4 - - [09/May/2013:13:32:23 +0300] "GET /feeds/stock.xml HTTP/1.0" 200 16202 "-" "-"
1.2.3.4 - - [09/May/2013:13:33:23 +0300] "GET /feeds/price.xml HTTP/1.0" 200 82143 "-" "-"
1.2.3.4 - - [09/May/2013:13:34:23 +0300] "GET /feeds/stock.xml HTTP/1.0" 200 16202 "-" "-"
::1 - - [09/May/2013:13:35:03 +0300] "GET / HTTP/1.1" 200 1007 "-" "Mozilla/5.0 (ISPConfig monitor)"
1.2.3.4 - - [09/May/2013:13:35:23 +0300] "GET /feeds/price.xml HTTP/1.0" 200 82143 "-" "-"
1.2.3.4 - - [09/May/2013:13:36:23 +0300] "GET /feeds/stock.xml HTTP/1.0" 200 16202 "-" "-"
1.2.3.4 - - [09/May/2013:13:37:23 +0300] "GET /feeds/price.xml HTTP/1.0" 200 82143 "-" "-"
1.2.3.4 - - [09/May/2013:13:38:23 +0300] "GET /feeds/stock.xml HTTP/1.0" 200 16202 "-" "-"
1.2.3.4 - - [09/May/2013:13:39:24 +0300] "GET /feeds/price.xml HTTP/1.0" 200 82143 "-" "-"
::1 - - [09/May/2013:13:40:03 +0300] "GET / HTTP/1.1" 200 1007 "-" "Mozilla/5.0 (ISPConfig monitor)"
1.2.3.4 - - [09/May/2013:13:40:24 +0300] "GET /feeds/stock.xml HTTP/1.0" 200 16202 "-" "-"
[...]

The function to reads the price from the xml file:

function get_price($product_id, $source='xml'){
    $price      = NULL;
    $url = "http://www.mydomain.com/feeds/price.xml";

    $xml = simplexml_load_file($url);
    $Price = $xml->xpath("//PRODUCT[@CODE='". $product_id ."']");

    return $price;
}

The function to read the stock xml is very similar.

All the configurations (MySQL, PHP, Apache) are nearly default configurations, nothing special. I have no idea why the read rate goes down after a while :(

Server Specs:

  • CentOS release 6.4 (Final)
  • ISPConfig 3.0.5.2
  • Apache/2.2.15 (Unix)
  • MySQL 5.1.69
  • PHP 5.3.3
Was it helpful?

Solution

dont use http to get the file,just call file directly

use this code

$url = "feeds/price.xml";

You can also use this code to get all the file in feeds directory and get all result in $Price variable

 $Price = "";
 foreach (glob("feeds/*.xml") as $filename) { //Getting all xml files from feeds direcotry
       $xml = simplexml_load_file("feeds/".$filename);
       $Price .= $xml->xpath("//PRODUCT[@CODE='". $product_id ."']");
  }
  print_r($Price);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top