Skip to content

Instantly share code, notes, and snippets.

@mtvbrianking
Created May 16, 2019 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtvbrianking/a41e11c08ca27675df2f1337f142c5b1 to your computer and use it in GitHub Desktop.
Save mtvbrianking/a41e11c08ca27675df2f1337f142c5b1 to your computer and use it in GitHub Desktop.
Extend Soap Client
<?php
/**
* @link https://gist.github.com/RobThree/2490351 Source #1
* @link https://gist.github.com/RobThree/4117914 Source #2
*/
class SafeSoapClient extends \SoapClient
{
public function __construct($wsdl, $options) {
parent::__construct($wsdl, $options);
}
public function __doRequest($request, $location, $action, $version, $one_way = false)
{
$response = parent::__doRequest($request, $location, $action, $version, $one_way);
}
}
try {
$wsdl = 'http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL';
$client = new SafeSoapClient($wsdl, [
'exceptions' => true,
'timeout' => 5,
]);
echo 'All is well.';
} catch ( SoapFault $e ) { // Do NOT try and catch "Exception" here
var_dump($e);
echo 'sorry... our service is down';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment