News | Halon

Making PHP’s SOAP client asynchronous – Halon

Written by Anders Berggren | Nov 27, 2013 11:00:00 PM

Most web projects uses client-side JavaScript to handle concurrency, because of its asynchronous and callback-based nature. In some cases however, it’s desirable to achieve concurrency on the server side. One example could be the processing of sensitive data, that has to be filtered before handed to the client. In our case, it was a data size issue that triggered us to implement a concurrent SOAP client. We develop a hosting-grade anti-spam appliance, and an open source end-user web interface that allows users to interact with a cluster of anti-spam systems. Imagine a cluster with 10 nodes, and a user that views the 100 latest messages. Using JavaScript, that would require the client to download a listing of 10*100 messages, and with PHP it would result in 10 synchronous request.

Thanks to PHP’s flexibility, we could develop a cross-platform solution, without having to rely on a RPC multiplexer. We chose a select()ing method provided by CURL’s “multi” package, by extending the SoapClient class and implementing our own __doRequest.

You can download our helper script, and use it as

// Just demonstrating that it works with multiple functions, to multiple servers
$client1 = new SoapClientAsync('some-systems-wsdl', $options);
$client2 = new SoapClientAsync('another-systems-wsdl', $options);
$client1->someFunction($arguments);
$client1->anotherFunction($arguments);
$client2->anotherFunction($arguments);
soap_dispatch();
$result1 = $client1->someFunction($arguments);
$result2 = $client1->anotherFunction($arguments);
$result3 = $client2->anotherFunction($arguments);

We hope that our customers appreciate the speed boost that it gives their anti-spam system’s end-user web interfaces.