Created
October 12, 2013 09:21
-
-
Save adri/6947827 to your computer and use it in GitHub Desktop.
soap example
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
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