Home > Impersonal > PHP SOAP client giving “Error Fetching http headers”

PHP SOAP client giving “Error Fetching http headers”

October 23rd, 2008

Summary: PHP’s SOAP client was throwing an extremely unhelpful error: Error Fetching http headers. It turns out that it was a simple case of a slow SOAP server, and increasing the default_socket_timeout in php.ini to 120 fixed it.

Problem: My very first experience with SOAP was failing. I couldn’t figure out why one request (getVersion) worked while another (getUserList) gave the above cryptic error.

Solution: After trying in vain to get useful information out of Apache and PHP, I installed Wireshark to sniff my network traffic. I could see the response coming in just fine, but it was only when I realized that it was coming in almost 100 seconds after the request that I became suspicious. Checking my php.ini, I found that the default_socket_timeout was set to 60 seconds. I upped it to 120 and the problem was resolved.

Discussion: I probably should have thought of a timeout earlier. It felt like a timeout, but the strange message about headers caused me to bash my head against a wall for the better part of a workday.

Using the SOAP client’s connection_timeout option in this case would most likely not work because this is not a connection timeout—the TCP connection is made just fine—but rather that the server takes too long to form its HTTP/SOAP response. This is why the call to getVersion ran without trouble while getUserList did not; getUserList had a much longer execution time on the server.

Aidan Findlater Impersonal , ,

  1. Anonymous
    February 18th, 2009 at 20:02 | #1

    Thanks - tried still gives error

  2. February 18th, 2009 at 21:47 | #2

    Well it’s a pretty general error. This is just what it turned out to be in my case. Have you tried using Wireshark to see what’s being sent between the client and the server?

  3. Andrew Metcalfe
    May 15th, 2009 at 11:47 | #3

    This fixed my problem. Thanks for the incredibly cryptic error PHP!

    And thanks for posting this aidan :). This one was giving me a headache because *sometimes* it would work, and sometimes it wouldn’t. Apparently my soap server works faster at certain times of the day :P

  4. Patricia
    May 27th, 2009 at 12:56 | #4

    It gave me a clue of my issue. I set that variable to 600. Thanks!

  5. Jason
    June 16th, 2009 at 09:33 | #5

    Thanks for this post. I’m having the same error. Was this ini change made on the host SOAP server or the client machine?

  6. June 17th, 2009 at 18:57 | #6

    On the client. I only had access to the host through the SOAP connection, so couldn’t adjust its timeout value.

  1. No trackbacks yet.