public function __doRequestByCurl($request, $location, $action, $version, $one_way = FALSE)
{
// Call via Curl and use the timeout a
$curl = curl_init($location);
if ($curl === false) {
throw new ClientException('Curl initialisation failed');
}
/** @var $headers array of headers to be sent with request */
$headers = array('User-Agent: PHP-SOAP', 'Content-Type: text/xml; charset=utf-8', 'SOAPAction: "' . $action . '"', 'Content-Length: ' . strlen($request));
$options = array(CURLOPT_VERBOSE => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $request, CURLOPT_HEADER => $headers, CURLOPT_HTTPHEADER => array(sprintf('Content-Type: %s', $version == 2 ? 'application/soap+xml' : 'text/xml'), sprintf('SOAPAction: %s', $action)));
// Timeout in milliseconds
$options = $this->__curlSetTimeoutOption($options, $this->timeout, 'CURLOPT_TIMEOUT');
// ConnectTimeout in milliseconds
$options = $this->__curlSetTimeoutOption($options, $this->connectTimeout, 'CURLOPT_CONNECTTIMEOUT');
$this->__setCurlOptions($curl, $options);
$response = curl_exec($curl);
if (curl_errno($curl)) {
$errorMessage = curl_error($curl);
$errorNumber = curl_errno($curl);
curl_close($curl);
throw new ClientException($errorMessage, $errorNumber);
}
$header_len = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_len);
$body = substr($response, $header_len);
curl_close($curl);
// Return?
if ($one_way) {
return null;
} else {
return $body;
}
}