PHP SOAP client giving "Error Fetching http headers"

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 defaultsockettimeout 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 defaultsockettimeout 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.


  1. Thanks - tried still gives error

  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. 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. It gave me a clue of my issue. I set that variable to 600. Thanks!

  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. On the client. I only had access to the host through the SOAP connection, so couldn't adjust its timeout value.

  7. Thank you, Aidan, you saved my day!

  8. Thanks Aidan, it solved my problem!

  9. if still error, try to set it as unlimited..
    fixed in my case

Leave your thoughts
  • You can use some HTML in your comment.
  • Your comment may not display immediately due to spam filtering. Please wait for moderation.