php SoapFault 异常:[HTTP] 获取 http 标头时出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4824799/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SoapFault exception: [HTTP] Error Fetching http headers
提问by Syed Tayyab Ali
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. so I set it as follow. default_socket_timeout = 480
我阅读了几篇文章,发现 default_socket_timeout 需要配置。所以我设置如下。default_socket_timeout = 480
I am still getting same error. Can someone help me out?
我仍然遇到同样的错误。有人可以帮我吗?
采纳答案by Syed Tayyab Ali
One of my process within web service was taking long time to execute. Therefore I was getting soapfault exeception.
我在 Web 服务中的一个过程需要很长时间才能执行。因此,我收到了肥皂错误异常。
回答by HNygard
I have been getting Error fetching http headers
for two reasons:
我一直有Error fetching http headers
两个原因:
- The server takes to long time to answer.
- 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. 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 将始终尝试通过发送Connection: Keep-Alive
HTTP 标头来使用与 Web 服务的持久连接。如果服务器总是关闭连接并且没有这样做(PHP 没有收到EOF
),则您可以Error fetching http headers
在 PHP 尝试重用服务器端已经关闭的连接时获取。
Note:this scenario will only happen if the same SoapClient
object sends more than one request and with a high frequency. Sending Connection: close
HTTP header along with the first request would have fixed this.
注意:这种情况只会发生在同一个SoapClient
对象以高频率发送多个请求的情况下。将Connection: close
HTTP 标头与第一个请求一起发送可以解决这个问题。
In PHP version 5.3.5 (currently delivered with Ubuntu) setting the HTTP header Connection: Close
is not supported by SoapClient. 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 solvedin PHP version 5.3.11).
在 PHP 版本 5.3.5(当前随 Ubuntu 一起交付)中Connection: Close
,SoapClient 不支持HTTP 标头设置。应该能够在流上下文中发送 HTTP 标头(使用$option
- 键stream_context
作为参数SoapClient
),但SoapClient
不支持更改连接标头(更新:此错误已在 PHP 5.3.11 版中解决)。
An other solution is to implement your own __doRequest()
. On the link provided, a guy uses Curl
to send the request. This will make your PHP application dependent on Curl
. The implementation is also missing functionality like saving request/response headers.
另一种解决方案是实现您自己的__doRequest()
. 在提供的链接上,一个人Curl
用来发送请求。这将使您的 PHP 应用程序依赖于Curl
. 该实现还缺少保存请求/响应标头等功能。
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()
. Example with __call()
:
第三种解决方案是在收到响应后立即关闭连接。这可以通过设置SoapClients属性来完成httpsocket
对NULL
中__doRequest()
,__call()
或__soapCall()
。示例__call()
:
class MySoapClient extends SoapClient {
function __call ($function_name , $arguments) {
$response = parent::__call ($function_name , $arguments);
$this->httpsocket = NULL;
return $response;
}
}
回答by MagentoMan
I had the same issue and tried the following by disabling 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. It appears to have been caching the wrong requests and after disabling I actually noticed my requests were executing faster.
然而,这对我不起作用。对我有用的是禁用 SOAP 缓存。它似乎缓存了错误的请求,在禁用后我实际上注意到我的请求执行得更快。
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.
service httpd reload
不要忘记重新加载apache。
service httpd reload