Created
May 10, 2012 15:53
-
-
Save dbaltas/2654079 to your computer and use it in GitHub Desktop.
Set Timeout on SOAP requests for https connections using curl on Zend Framework
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
function simulateSoapRequest($request, $location, $action, $version) | |
{ | |
$client = new Zend_Http_Client($location); | |
$adapter = new Zend_Http_Client_Adapter_Curl(); | |
$client->setAdapter($adapter); | |
$adapter->setCurlOption(CURLOPT_TIMEOUT, $this->_timeout); | |
$client->setMethod(Zend_Http_Client::POST); | |
$client->setHeaders('Content-Type', $version == 2 ? 'application/soap+xml' : 'text/xml'); | |
$client->setHeaders('SOAPAction', $action); | |
$client->setRawData($request); | |
try { | |
$client->request(); | |
} catch (Exception $e) { | |
$code = $e->getCode(); | |
throw (new SoapFault($code = $code ? $code : 'curl error', $e->getMessage())); | |
} | |
$client->getLastRequest(); | |
if ($client->getLastResponse() != null) { | |
$response = $client->getLastResponse()->getBody(); | |
} | |
return $response; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment