Created
July 20, 2011 16:21
-
-
Save xeoncross/1095286 to your computer and use it in GitHub Desktop.
Custom SOAP client request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // http://www.darqbyte.com/2009/10/21/timing-out-php-soap-calls/ | |
| // Uses cURL instead of default SOAP request method to allow timeouts of problem requests | |
| class SoapClientTimeout extends SoapClient | |
| { | |
| private $timeout; | |
| public function __setTimeout($timeout) | |
| { | |
| if (!is_int($timeout) && !is_null($timeout)) | |
| { | |
| throw new Exception("Invalid timeout value"); | |
| } | |
| $this->timeout = $timeout; | |
| } | |
| public function __doRequest($request, $location, $action, $version, $one_way = FALSE) | |
| { | |
| if (!$this->timeout) | |
| { | |
| // Call via parent because we require no timeout | |
| $response = parent::__doRequest($request, $location, $action, $version, $one_way); | |
| } | |
| else | |
| { | |
| // Call via Curl and use the timeout | |
| $curl = curl_init($location); | |
| curl_setopt($curl, CURLOPT_VERBOSE, FALSE); | |
| curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); | |
| curl_setopt($curl, CURLOPT_POST, TRUE); | |
| curl_setopt($curl, CURLOPT_POSTFIELDS, $request); | |
| curl_setopt($curl, CURLOPT_HEADER, FALSE); | |
| curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: text/xml")); | |
| curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout); | |
| $response = curl_exec($curl); | |
| if (curl_errno($curl)) | |
| { | |
| throw new Exception(curl_error($curl)); | |
| } | |
| curl_close($curl); | |
| } | |
| // Return? | |
| if (!$one_way) | |
| { | |
| return ($response); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment