PHP:SoapClient构造函数非常慢(需要3分钟) [英] PHP: SoapClient constructor is very slow (takes 3 minutes)

查看:117
本文介绍了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分钟。我不知道问题是什么。在创建构造函数之后,我可以在 for 循环中使用它,在1秒内循环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?

提前谢谢。

PS:
我在其他问题中的更多信息:
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(...)来插入服务器日期连接 -header。

Now I just need to find out how to force the Endpoint.publish(...) to insert a Server, Date, or Connection-header.

(编辑)我找到了一个解决方案:问题不仅在于Chunked数据,还在于Keep-Alive。这可以通过在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'
                        )
                    )
                )
            )
        );
    }
}

这篇关于PHP:SoapClient构造函数非常慢(需要3分钟)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆