Skip to content

Instantly share code, notes, and snippets.

@adri
Created October 12, 2013 09:21
Show Gist options
  • Save adri/6947827 to your computer and use it in GitHub Desktop.
Save adri/6947827 to your computer and use it in GitHub Desktop.
soap example
class TimeoutSoapClient extends SoapClient
{
const TIMEOUT = 20;
public function __doRequest($request, $location, $action, $version, $one_way = 0)
{
$url_parts = parse_url($location);
$host = $url_parts['host'];
$http_req = 'POST '.$location.' HTTP/1.0'."\r\n";
$http_req .= 'Host: '.$host."\r\n";
$http_req .= 'SoapAction: '.$action."\r\n";
$http_req .= "\r\n";
$http_req .= $request;
$port = 80;
if ($url_parts['scheme'] == 'https')
{
$port = 443;
$host = 'ssl://'.$host;
}
$socket = fsockopen($host, $port);
fwrite($socket, $request);
stream_set_blocking($socket, false);
$response = '';
$stop = microtime(true) + self::TIMEOUT;
while (!feof($socket))
{
$response .= fread($socket, 2000);
if (microtime(true) > $stop)
{
throw new SoapFault('Client', 'HTTP timeout');
}
}
return $response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment