【发布时间】:2015-07-29 23:21:45
【问题描述】:
我需要使用soap 请求检索大量远程数据(检索大约12000 个交货订单,并为每个单独的订单发出请求)。在我的测试服务器(带有 Xampp 的 Windows)上,它运行良好,大约需要一个小时左右。将脚本放在生产服务器 (Linux) 上,大约 10 分钟后连接断开(它会有所不同)。
我尝试将标题从“Connection: Close”更改为“Connection: Keep-Alive”,但这使得检索每条记录的速度因某种原因变得如此缓慢——比如每分钟 3 条记录而不是 170 条记录。注意确定是因为 fputs 还是 fgets-loop。
谁能告诉我如何强制连接在给定时间段内保持活动状态?
基本上我的脚本是:
if (!is_resource($fp))
{
$fp = @fsockopen($host, $port, $errno, $errstr);
if (!$fp) { echo "soap_parser error message is: $errstr ($errno)<br />\n";exit;}
stream_set_timeout($fp,3600);//one hour
}
$soap_out = "POST " . $path . " HTTP/1.1\r\n";
$soap_out .= "Host: " . $hostname . "\r\n";
$soap_out .= "User-Agent: MYSOAPREQUEST \r\n";
$soap_out .= "Content-Type: text/xml;charset=UTF-8;\r\n";
$soap_out .= "Content-Length: ".strlen($xml_request)."\r\n";
$soap_out .= "Connection: Close\r\n";
$soap_out .= "Cache-Control: no-cache\r\n";
$soap_out .= "SOAPAction: ".$soap_action."\r\n\r\n";
$soap_out .= $xml_request;
fputs($fp, $soap_out); //send request SOAP
$soap_in = "";
while (!feof($fp))
{
$soap_in .= fgets($this->fp, 512);
}
return $soap_in;
【问题讨论】:
-
你在 php.ini 中的超时设置是什么?
-
在我的页面顶部我有:| set_time_limit(60*130);也许我应该考虑其他设置?
-
在 PHP 中有很多需要考虑的地方。 php.net/manual/en/info.configuration.php#ini.max-execution-time 是另一个明显的例子。