Reputation: 1623
I am connecting to a webservice to get some data. I have a queue of requests with about 200K jobs and a worker is handling it. Process time is 2-3 calls per second. After about 500-1000 calls, it starts getting SoapFault exception with this message: Could not connect to host
. Even when I get this error I am able to ping the webservice server properly.
When I disable soap cache, the problem is still there but the error changes to Parsing WSDL: Couldn't load from 'http://thewebservice.com/method/Service.asmx?WSDL' : failed to load external entity
Connection code:
$client = new SoapClient('http://thewebservice.com/method/Service.asmx?WSDL');
$response = $client->__soapCall('method name', $parameters)
I work with:
Upvotes: 3
Views: 3790
Reputation: 5269
Are you creating a new SoapClient instance for every call? In that case, disabling keep_alive
is only a workaround and this could be improved.
SoapClient sends the HTTP Header Connection: Keep-Alive
by default (through the constructor option keep_alive
). But if you create a new SoapClient instance for every call in your queue, this will create and keep-open a new connection everytime. If the calls are executed fast enough, you will eventually run into a limit of 1000 open connections or so and this results in SoapFault: Could not connect to host
.
So make sure you create the SoapClient once and reuse it for subsequent calls.
Upvotes: 1
Reputation: 1623
In my case, the problem was too many open connections at the same time. I fixed it by keep_alive
option:
$client = new SoapClient('http://thewebservice.com/method/Service.asmx?WSDL', ['keep_alive' => false]);
$response = $client->__soapCall('method name', $parameters)
Upvotes: 5