我正在尝试通过xml文件中的产品代码(也来自数据库表)读取价格表和库存清单,并将结果放入MySQL表中。
除了xml文件的响应或读取时间外,一切正常。 PHP脚本,数据库和XML文件位于同一服务器上。看了一下Apache access.log后,我看到PHP脚本启动后可以非常快速地读取(或响应)。但过了一段时间,它每分钟只读取1个:
[...]
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 "-" "-"
[...]
从xml文件中读取价格的功能:
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;
}
读取股票xml的功能非常相似。
所有配置(MySQL,PHP,Apache)几乎都是默认配置,没什么特别的。我不知道为什么读取率会在一段时间后下降:(
服务器规格:
答案 0 :(得分:1)
不要使用http来获取文件,只需直接调用文件
使用此代码
$ url =“feeds / price.xml”;
您还可以使用此代码获取Feed目录中的所有文件,并获得$ Price变量
中的所有结果 $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);