dsbo44836129 2016-01-06 23:51
浏览 156

PHP SOAP非常慢:仅在达到fastcgi_read_timeout后才响应

The constructor of the SOAP client in my wsdl web service is awfully slow, I get the response only after the fastcgi_read_timeout value in my Nginx config is reached, it seems as if the remote server is not closing the connection. I also need to set it to a minimum of 15 seconds otherwise I will get no response at all.

I already read similar posts here on SO, especially this one PHP SoapClient constructor very slow and it's linked threads but I still cannot find the actual cause of the problem.

This is the part which takes 15+ seconds:

$client = new SoapClient("https://apps.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl");

It seems as it is only slow when called from my php script, because the file opens instantly when accessed from one of the following locations:

  • wget from my server which is running the script
  • SoapUI or Postman (But I don't know if they cached it before)
  • opening the URL in a browser

Ports 80 and 443 in the firewall are open. Following the suggestion from another thread, I found two work arounds:

  • Loading the wsdl from a local file => fast
  • Enabling the wsdl cache and using the remote URL => fast

But still I'd like to know why it doesn't work with the original URL.

It seems as if the web service does not close the connection, or in other words, I get the response only after reaching the timeout set in my server config. I tried setting keepalive_timeout 15; in my Nginx config, but it does not work.

Is there any SOAP/PHP parameter which forces the server to close the connection?

  • 写回答

1条回答 默认 最新

  • dongni8969 2016-01-07 00:14
    关注

    I was able to reproduce the problem, and found the solution to the issue (works, maybe not the best) in the accepted answer of a question linked in the question you referenced:

    PHP: SoapClient constructor is very slow (takes 3 minutes)

    As per the answer, you can adjust the HTTP headers using the stream_context option.

    $client = new SoapClient("https://apps.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl",array(
        'stream_context'=>stream_context_create(
            array('http'=>
                array(
                    'protocol_version'=>'1.0',
                    'header' => 'Connection: Close'
                )
            )
        )
    ));
    

    More information on the stream_context option is documented at http://php.net/manual/en/soapclient.soapclient.php

    I tested this using PHP 5.6.11-1ubuntu3.1 (cli)

    评论

报告相同问题?

悬赏问题

  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像