I'm running a PHP queue worker process that processes jobs that in turn create SOAP clients and perform SOAP requests. I'll try to outline the pseudo-code as clearly as possible.
Jobs and parameters are saved to the database an get instantiated by the worker. In simplified form, the worker looks like this:
while(true) {
$job = initiateFromDatabase($id);
$job->handle()
}
For a certain job a SOAPClient is instantiated and a SOAP call is performed. Some results are saved to a database.
The problem is that the process will pretty soon hit the open file descriptor limit. After some inspection with lsof -a -p <worker_pid> there are hundreds of TCP descriptors hanging in CLOSE_WAIT.
I've done intensive research and my conclusion is that there is no way to explicitly close the SOAP connection (and underlying) socket.
The only way to clear the hundreds of CLOSE_WAIT descriptors is to just kill the worker process.
How can I make sure I can run the worker for larger periods of time and make the CLOSE_WAIT descriptors disappear after the SOAPClient instance is not used anymore?
Thanks in advance.
I solved the issue by setting keep_alive option to false
$client = new SoapClient($wsdl_url, array('keep_alive'=>false));