[php] Uncaught SoapFault exception: [HTTP] Error Fetching http headers

I'm trying to create a soap connection to Magento's web services, however I'm getting an error when I try and create an instance of the soap client class. I can view the wsdl file in firefox without problems and I can watch php make the request for the wsdl in apaches logs but it still fails. Nusoap can connect.

$proxy = new SoapClient('someaddress?wsdl');

The error is

<b>Fatal error</b>:  Uncaught SoapFault exception: [HTTP] Error Fetching http headers in /home/sites/xxx/xxx_main/system/application/views/contentpage_templates/gift_service.php:29
Stack trace:
[internal function]: SoapClient-&gt;__doRequest('&lt;?xml version=&quot;...',    'http://cornishw...', 'urn:Mage_Api_Mo...', 1, 0)
[internal function]: SoapClient-&gt;__call('call', Array)
/home/sites/xxx/xxx_main/system/application/views/contentpage_templates/gift_service.php(29): SoapClient-&gt;call(NULL, 'catalog_categor...', 5, 'giftshop')
/home/sites/xxx/xxx_main/system/application/libraries/MY_Loader.php(586): include('/home/sites/cor...')
/home/sites/xxx/xxx_main/system/application/libraries/MY_Loader.php(228): MY_Loader-&gt;_ci_load(Array, '')
/home/sites/xxx/xxx_main/system/application/modules/contentpage/controllers/contentpage.php(44): MY_Loader-&gt;view('contentpage_tem...', false, true)
[internal function]: Contentpage-&gt;index()
/home/sites/xxx in <b>/home/sites/xxx/xxx_main/system/application/views/contentpage_templates/gift_service.php</b> on line <b>29</b>

Thanks

This question is related to php soap magento wsdl

The answer is


I faced same problem and tried all the above solution. Sadly nothing work.

  1. Socket Timeout (Not worked)
  2. User Agent (Not Worked)
  3. SoapClient configuration, cache_wsdl and Keep-Alive etc..

This whole game of headers that we are passing. I solved my problem with adding the compression header property. This actually require when you are expecting 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.


I faced the same problem.
I was running It as CLI. So PHP was always running and it had to make soap call again and again after some interval.
The mistake I did was using singleton pattern for this. I thought use of singleton will cause performance boost but inturn I got

Error Fetching http headers in ...

I fixed it by creating new saop object for each call.


Please update your php.ini with

default_socket_timeout = 120

You can create your own php.ini if php is installed a CGI instead of a Apache module


If this is a Magento related problem, you should turn off automatic re-indexing as this could be causing the socket to timeout (or expire). You can turn it back on once the script has finished its tasks. Increasing the default socket timeout in php.ini is also a good idea.


Did you try adding

'trace'=>1,

to SoapClient creation parameters and then:

var_dump($client->__getLastRequest());
var_dump($client->__getLastResponse());

to see what is going on?


There is an issue in php version less than 5.2.6. You may need to upgrade the version of php.


I am not about your PHP configuration but until PHP 5.2.6 , PHP does have some problem with SOAP client :

Bug #41983 - Error Fetching http headers

Bug #41983


In my apache error log, I saw:

[Tue Feb 16 14:55:02 2010] [notice] child pid 9985 exit signal File size limit exceeded (25)

So I, removed all the contents of my largest log file 2.1GB /var/log/system.log. Now everything works.


This error can appear on the client if there is a problem on the server side. For example, if the SOAP server is a PHP script with a parse error, the client will fail with this message.

If you are in control of the server, tail your Apache error_log on the machine that hosts the SOAP server. On CentOS you will find this in /var/log/httpd/error_log, so the command is:

tail -f /var/log/httpd/error_log

Now refresh the client and watch for the error message. Any PHP errors with the server script will be shown.

Hope that helps someone.


Examples related to php

I am receiving warning in Facebook Application using PHP SDK Pass PDO prepared statement to variables Parse error: syntax error, unexpected [ Preg_match backtrack error Removing "http://" from a string How do I hide the PHP explode delimiter from submitted form results? Problems with installation of Google App Engine SDK for php in OS X Laravel 4 with Sentry 2 add user to a group on Registration php & mysql query not echoing in html with tags? How do I show a message in the foreach loop?

Examples related to soap

No found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: There was no endpoint listening at (url) that could accept the message How to enable SOAP on CentOS SOAP-ERROR: Parsing WSDL: Couldn't load from - but works on WAMP SOAP vs REST (differences) SOAP request to WebService with java How to consume a SOAP web service in Java Sending SOAP request using Python Requests JSON, REST, SOAP, WSDL, and SOA: How do they all link together What is the difference between JAX-RS and JAX-WS?

Examples related to magento

Where are Magento's log files located? find . -type f -exec chmod 644 {} ; Get product id and product type in magento? There has been an error processing your request, Error log record number Class 'DOMDocument' not found Magento: Set LIMIT on collection How to remove index.php from URLs? Get skin path in Magento? SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1922-1' for key 'IDX_STOCK_PRODUCT' Service Temporarily Unavailable Magento?

Examples related to wsdl

Generating Request/Response XML from a WSDL How to generate xsd from wsdl How do you convert WSDLs to Java classes using Eclipse? How to get the wsdl file from a webservice's URL JSON, REST, SOAP, WSDL, and SOA: How do they all link together Difference between a SOAP message and a WSDL? SOAP PHP fault parsing WSDL: failed to load external entity? How to do a SOAP wsdl web services call from the command line Importing xsd into wsdl SoapUI "failed to load url" error when loading WSDL