PHP:SoapClient 构造函数很慢(需要 3 分钟)
我是 PHP 新手.经过大量搜索,我设法以某种方式使用由 Java 和 PHP 创建的 Web 服务,但问题是 SoapClient 类的构造函数非常慢.这是我的 PHP 代码:
I'm new to PHP. After lots of search I managed to somehow use my web service that is created by Java with PHP but the problem is the constructor of SoapClient class is very slow. Here's my PHP code:
<?
require_once('SOAP/Client.php');
$url = "http://127.0.0.1:8024/_RS?wsdl";
$sc = new SoapClient($url);
?>
有时最多需要 3 分钟.我不知道是什么问题.创建构造函数后,我可以在 1 秒内在 for
循环中使用它 50 次,所以我很确定构造函数是减慢我的代码的部分.
This takes up to 3 minutes some times. I don't know what the problem is. After creating the constructor I could use it in a for
loop for 50 times in 1 second so I'm pretty sure that the constructor is the part that is slowing down my code.
您认为导致问题的原因是什么?
What do you think is causing the problem?
提前致谢.
附注:我的另一个问题中的更多信息:https://stackoverflow.com/questions/5929669/call-a-wsdl-web-service-created-by-java-from-nushphere-phped
PS: More information in my other question: https://stackoverflow.com/questions/5929669/call-a-wsdl-web-service-created-by-java-from-nushphere-phped
PPS:按照 AJ 的建议,我使用 XDebug 和 kcachegrind 来分析问题.如你所见,我是对的.这是图片:
PPS: As suggested by AJ, I used XDebug and kcachegrind to analyze the problem. As you can see, I was right. Here's the picture:
我有同样的问题.php SoapClient 与部署在 Tomcat 上的相同 web 服务非常快.我尝试执行wget"以查看响应中的标头是否不同,并且问题在于 WSDL 缓存我发现的差异可能是原因:
I have the same problem. The php SoapClient is very fast with the same webservice deployed on Tomcat. I tried doing a "wget" to see if the headers in the response was different and as the problem is with the WSDL caching the difference I found might be the reason:
使用 Tomcat:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/xml;charset=utf-8
Content-Length: 23925
Date: Thu, 08 Mar 2012 23:13:10 GMT
Connection: keep-alive
使用 Endpoint.publish(...)
With Endpoint.publish(...)
HTTP/1.1 200 OK
Content-type: text/xml;charset=utf-8
Content-length: 23837
现在我只需要找出如何强制 Endpoint.publish(...)
插入一个 Server
、Date
,或 Connection
-header.
Now I just need to find out how to force the Endpoint.publish(...)
to insert a Server
, Date
, or Connection
-header.
(编辑)我找到了一个解决方案:问题不仅与分块数据有关,而且与保持活动"有关.这可以通过在 stream_context 中设置标题Connection: Close"来防止.请看下图:
(Edit) I found a solution: The issue is not only with Chunked data but with "Keep-Alive". This can be prevented by setting the header "Connection: Close" in a stream_context. Please see below:
class ImprovedSoapClient extends SoapClient
{
public function __construct($wsdlLocation)
{
parent::__construct(
$wsdlLocation
, array(
, 'cache_wsdl' => WSDL_CACHE_NONE
, 'stream_context'=>stream_context_create(
array('http'=>
array(
'protocol_version'=>'1.0'
, 'header' => 'Connection: Close'
)
)
)
)
);
}
}