Skip to content

Instantly share code, notes, and snippets.

@dbaltas
Created May 10, 2012 15:53
Show Gist options
  • Save dbaltas/2654079 to your computer and use it in GitHub Desktop.
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
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