I\'m trying to invoke a WS over https on a remote host:remote port and I get:
Error fetching http headers
using the PHP5 SoapCli
This error is often seen when the default_socket_timeout
value is exceeded for the SOAP response. (See this link.)
Note from the SoapClient constructor: the connection_timeout
option is used for defining a timeout value for connecting to the service, not for the timeout for its response.
You can increase it like so:
ini_set('default_socket_timeout', 600); // or whatever new value you want
This should tell you if the timeout is the issue, or whether you have a different problem. Bear in mind that you should not use this as a permanent solution, but rather to see if it gets rid of the error before moving on to investigate why the SOAP service is responding so slowly. If the service is consistently this slow, you may have to consider offline/batch processing.
I got this same error and in my case the server I was sending the request to was replying with a 504 Gateway Time-out error. I didn't realize this until I went to the URL in a browser that was being requested by the SOAP request:
eg. https://soap-request-domain-here.com/path/to/file.wsdl
I had this problem and I checked, and in my case, was the Firewall. The PHP not show the error correctly. To perform the request, the Firewall answered:
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
...
<html
...
<h1>Direct Access IP is not allowed</h1>
...
</html>
The SoapClient expects the SOAP envelope but receives a HTML code. That's why PHP responds with: "Error Fetching Http Headers" because it can not understand what he received in response. To resolve the problem, contact your network administrator to verify if there is any Firewall, NAT or proxy getting in the way and then ask them to make the necessary arrangements.
In recent releases from Zend SOAP client not having "connection_timeout" and "Keep_alive" parameters at all.
You can see the piece of code I have attached as an image. The only way to solve this issue to increase your default socket timeout in php.ini
default_socket_timeout = 1000
I hope it will solve your issue. Give an upvote if it works.
I faced same problem and tried all the above solutions. Sadly nothing worked.
I solved my problem with adding the compression header property. This is actually required when you are expecting a response in gzip compressed format.
//set the Headers of Soap Client.
$client = new SoapClient($wsdlUrl, array(
'trace' => true,
'keep_alive' => true,
'connection_timeout' => 5000,
'cache_wsdl' => WSDL_CACHE_NONE,
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | SOAP_COMPRESSION_DEFLATE,
));
Hope it helps.
Good luck.
None of the above techniques worked for me.
When I analyzed the request header from __getLastRequestHeaders, I saw the following:
POST /index.php/api/index/index/?SID=012345 HTTP/1.1
Host: www.XYZ.com
The API URL I had been using was different, like www.ABC.com. I changed the API URL to www.XYZ.com/index.php/api?wsdl, and then it worked.
Both URLs returned the same WSDL from the same server, but only one allowed login.