title: PHP SOAP - Expanding __doRequest
body: <p>I am trying to expand PHP's \SoapClient to include timeout and retry capabilities...I have tried to implement both of the following two scripts without any success</p>
  
  <p><a href="https://github.com/ideaconnect/idct-soap-client/blob/master/src/client.php" rel="nofollow">https://github.com/ideaconnect/idct-soap-client/blob/master/src/client.php</a></p>
  
  <p><a href="https://gist.github.com/RobThree/2490351" rel="nofollow">https://gist.github.com/RobThree/2490351</a></p>
  
  <p>The strange thing is, a completely default soap request works perfectly for me.  The following script also works perfectly for me...</p>
  
  <pre><code>class SoapTest extends \SoapClient {
  
      public function __construct($wsdl, $options) {  
          parent::__construct($wsdl,$options);
      }
  
      public function __doRequest ($request, $location, $action, $version, $one_way = null) {
        $response = parent::__doRequest($request, $location, $action, $version, $one_way);
        return $response;
      }
  
  }
  </code></pre>
  
  <p>However when I start trying to implement my own __doRequest code I can't get it working no matter the hundred variations I have tried.  Below is one of the snippets I have tried, does anyone know the default options/lines I need to use to make it behave natively?</p>
  
  <pre><code>        $curl = curl_init($location);
          $options = array(
              CURLOPT_VERBOSE =&gt; true,
              CURLOPT_RETURNTRANSFER =&gt; true,
              CURLOPT_POST =&gt; true,
              CURLOPT_POSTFIELDS =&gt; $request,
              CURLOPT_HEADER =&gt; false,
              CURLOPT_NOSIGNAL =&gt; false,
              CURLOPT_HTTPHEADER =&gt; array(sprintf('Content-Type: %s', $version == 2 ? 'application/soap+xml' : 'text/xml'), sprintf('SOAPAction: %s', $action)),
              CURLOPT_SSL_VERIFYPEER =&gt; $this-&gt;sslverifypeer
          );
  
          if ($this-&gt;timeout&gt;0) {
              if (defined('CURLOPT_TIMEOUT_MS')) {    //Timeout in MS supported?
                  $options[CURLOPT_TIMEOUT_MS] = $this-&gt;timeout;
              } else  { //Round(up) to second precision
                  $options[CURLOPT_TIMEOUT] = ceil($this-&gt;timeout/1000);
              }
          }
  
          if ($this-&gt;connecttimeout&gt;0) {
              if (defined('CURLOPT_CONNECTTIMEOUT_MS')) { //ConnectTimeout in MS supported?
                  $options[CURLOPT_CONNECTTIMEOUT_MS] = $this-&gt;connecttimeout;
              } else { //Round(up) to second precision
                  $options[CURLOPT_CONNECTTIMEOUT] = ceil($this-&gt;connecttimeout/1000);
              }
          }
  
          if (curl_setopt_array($curl, $options) === false)
              throw new Exception('Failed setting CURL options');
  
          $response = curl_exec($curl);
  </code></pre>
  
  <p>Thanks for any help you can provide.</p>