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

报告相同问题?

悬赏问题

  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?