dua6992 2011-05-10 00:55
浏览 59
已采纳

PHP:SoapClient构造函数很慢(需要3分钟)

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);
?>

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?

Thank you in advance.

PS: More information in my other question: https://stackoverflow.com/questions/5929669/call-a-wsdl-web-service-created-by-java-from-nushphere-phped

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: XDebug result in kcachegrind both in % (up) and time(down).

  • 写回答

3条回答 默认 最新

  • dongqigu0429 2012-03-08 23:23
    关注

    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:

    With 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
    

    With Endpoint.publish(...)

    HTTP/1.1 200 OK
    Content-type: text/xml;charset=utf-8
    Content-length: 23837
    

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

    (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'
                            )
                        )
                    )
                )
            );
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 arduino控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥85 maple软件,solve求反函数,出现rootof怎么办?
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题