Thursday, 15 September 2016

PHP SOAP Fault: Error fetching http headers - tweak default_socket_timeout

Started getting the above error on some servers that communicate via soap. I control both ends, so I was pretty sure it wasn't a code issue. After searching round and experimenting I discovered that the query that produced the results that the soap server was being asked to supply could, under heavy load conditions, take longer than 60s, and the connection was dropping at the 60s mark.

Turns out this is the default for the PHP ini variable default_socket_timeout.

I reset it to zero - bad move. 0 = timeout after zero seconds.
    ini_set("default_socket_timeout",0);
I reset it to 3600 = an hour and all seems OK.
    ini_set("default_socket_timeout",3600);

Note that the SOAP method is being called by a crontab-scheduled batch script, so waiting a l-o-n-g time for results is perfectly OK in this case. Might not be if there was a person on the other end! ;)

No comments:

Post a Comment