Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php soap error fetching http headers

I am working on a PHP script that's processing a lot of data through a SOAP connection. Estimates of the total run time of the script look to be several days if it doesn't encounter any errors. The problem I'm running into is the script will run for a while, anywhere from an hour to a day, and then the SOAP connection will die with the error "error fetching http headers".

I've seen many articles suggesting increasing the default_socket_timeout setting and I've tried this. It hasn't helped. I know it's working cause it makes at least a hundred successful calls before it fails. Is there anything i can do to stop this error?

Update
I printed out the request and response headers hoping to see an error in there. But it appears they are fine:

HTTP/1.1 200 OK
Date: Wed, 25 Sep 2013 21:00:12 GMT
Server: Apache/2.2.15 (CentOS)
X-Powered-By: PHP/5.3.3
Content-Length: 516
Connection: close
Content-Type: text/xml; charset=UTF-8

as far as example code goes the actual script is crazy long, but the basic premise is this:

ini_set('default_socket_timeout', 120);
$client = new SoapClient($wsdl,array(
    'trace' =>true,
    'connection_timeout' => 500000,
    'cache_wsdl' => WSDL_CACHE_BOTH,
    'keep_alive' => true,
));
while(!$finished) {
    $finished = $client->someSoapFunction($data);
}

someSoapFunction() will return valid data for 100 of connections and then randomly return me the above error. The time it runs for is less than either of the set timeouts. I'm getting no errors in my php or apache error logs. I'm stumped.

like image 379
Jason Neumann Avatar asked Sep 25 '13 16:09

Jason Neumann


1 Answers

I know it is an old question, but perhaps my solution can be useful to others. I had the same problem and by changing the 'keep_alive' parameter to false in the creation of the SoapClient object, my problem was solved:

$client = new SoapClient($wsdl,array(
'trace' =>true,
'connection_timeout' => 500000,
'cache_wsdl' => WSDL_CACHE_BOTH,
'keep_alive' => false,
));
like image 181
user3240252 Avatar answered Sep 22 '22 16:09

user3240252