简体   繁体   English

SoapFault异常:[HTTP]错误获取http标头

[英]SoapFault exception: [HTTP] Error Fetching http headers

I am getting following exception in my php page. 我在php页面中遇到异常。

SoapFault exception: [HTTP] Error Fetching http headers SoapFault异常:[HTTP]错误获取http标头

I read couple of article and found that default_socket_timeout needs configuration. 我读了几篇文章,发现default_socket_timeout需要配置。 so I set it as follow. 所以我把它设置如下。 default_socket_timeout = 480 default_socket_timeout = 480

I am still getting same error. 我仍然得到同样的错误。 Can someone help me out? 有人可以帮我吗?

I have been getting Error fetching http headers for two reasons: 我一直收到Error fetching http headers有两个原因:

  1. The server takes to long time to answer. 服务器需要很长时间才能回答。
  2. The server does not support Keep-Alive connections (which my answer covers). 服务器不支持Keep-Alive连接(我的答案涵盖)。

PHP will always try to use a persistent connection to the web service by sending the Connection: Keep-Alive HTTP header. PHP将始终尝试通过发送Connection: Keep-Alive HTTP标头来使用与Web服务的持久连接。 If the server always closes the connection and has not done so (PHP has not received EOF ), you can get Error fetching http headers when PHP tries to reuse the connection that is already closed on the server side. 如果服务器总是关闭连接但尚未关闭(PHP没有收到EOF ),那么当PHP尝试重用已在服务器端关闭的连接时,您可以获取Error fetching http headers

Note: this scenario will only happen if the same SoapClient object sends more than one request and with a high frequency. 注意:仅当相同的SoapClient对象发送多个请求且频率较高时,才会出现此情况。 Sending Connection: close HTTP header along with the first request would have fixed this. 发送Connection: close HTTP标头以及第一个请求将修复此问题。

In PHP version 5.3.5 (currently delivered with Ubuntu) setting the HTTP header Connection: Close is not supported by SoapClient. 在PHP版本5.3.5(当前随Ubuntu提供)中,SoapClient不支持设置HTTP标头Connection: Close One should be able to send in the HTTP header in a stream context (using the $option - key stream_context as argument to SoapClient ), but SoapClient does not support changing the Connection header ( Update: This bug was solved in PHP version 5.3.11). 一个人应该能够在流上下文中发送HTTP头(使用$option - key stream_context作为SoapClient参数),但是SoapClient不支持更改Connection头更新:这个bug在PHP版本5.3.11中得到了解决) )。

An other solution is to implement your own __doRequest() . 另一种解决方案是实现自己的__doRequest() On the link provided, a guy uses Curl to send the request. 在提供的链接上,一个人使用Curl发送请求。 This will make your PHP application dependent on Curl . 这将使您的PHP应用程序依赖于Curl The implementation is also missing functionality like saving request/response headers. 该实现还缺少保存请求/响应头等功能。

A third solution is to just close the connection just after the response is received. 第三种解决方案是在收到响应后立即关闭连接。 This can be done by setting SoapClients attribute httpsocket to NULL in __doRequest() , __call() or __soapCall() . 这可以通过在__doRequest()__doRequest() __call()__soapCall() __doRequest() SoapClients属性httpsocket设置为NULL来完成。 Example with __call() : __call()示例:

class MySoapClient extends SoapClient {
    function __call ($function_name , $arguments) {
        $response = parent::__call ($function_name , $arguments);
        $this->httpsocket = NULL;
        return $response;
    }
}

I had the same issue and tried the following by disabling keep_alive . 我遇到了同样的问题,并通过禁用keep_alive尝试了以下keep_alive

$api_proxy = new SoapClient($api_url, array('trace' => true, 'keep_alive' => false));

However, that didn't work for me. 但是,这对我不起作用。 What worked worked for me was disabling the SOAP cache. 对我有用的是禁用SOAP缓存。 It appears to have been caching the wrong requests and after disabling I actually noticed my requests were executing faster. 它似乎缓存了错误的请求,在禁用后我实际上发现我的请求执行得更快。

On a linux server you can find this in your /etc/php.ini file. 在Linux服务器上,您可以在/etc/php.ini文件中找到它。

Look for soap.wsdl_cache_enabled=1 and change it to soap.wsdl_cache_enabled=0 . 查找soap.wsdl_cache_enabled=1并将其更改为soap.wsdl_cache_enabled=0

Don't forget to reload apache. 别忘了重装apache。 service httpd reload

One of my process within web service was taking long time to execute. 我在Web服务中的一个过程是花费很长时间来执行。 Therefore I was getting soapfault exeception. 因此我得到了soapfault的例外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM