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

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条)

报告相同问题?

悬赏问题

  • ¥50 adb连接不到手机是怎么回事?
  • ¥15 vs2022无法联网
  • ¥15 TCP的客户端和服务器的互联
  • ¥15 VB.NET操作免驱摄像头
  • ¥15 笔记本上移动热点开关状态查询
  • ¥85 类鸟群Boids——仿真鸟群避障的相关问题
  • ¥15 CFEDEM自带算例错误,如何解决?
  • ¥15 有没有会使用flac3d软件的家人
  • ¥20 360摄像头无法解绑使用,请教解绑当前账号绑定问题,
  • ¥15 docker实践项目