How to set SSL version when sending requests via SoapClient?

Every now and then you are required to work on a API which is pretty big. However, the SSL version they have used is depreciated one so you cannot use standard SoapClient class to communicate with them. The following snippet allows you to create your wrapper class which extends SoapClient and allows you to execute a curl request with the correct SSL version. Thus allowing you to make a successful communication with that API

class WrapperClass extends SoapClient {
    protected function callCurl($url, $data, $action) {
        $handle = curl_init();
        curl_setopt($handle, CURLOPT_URL, $url);
        curl_setopt($handle, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml", 'SOAPAction: "' . $action . '"'));
        curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
        curl_setopt($handle, CURLOPT_SSLVERSION, 3);
        $response = curl_exec($handle);
        if (empty($response)) {
            throw new SoapFault('CURL error: '.curl_error($handle),curl_errno($handle));
        return $response;

    public function __doRequest($request,$location,$action,$version,$one_way = 0) {
        return $this->callCurl($location, $request, $action);

Read More