Created
May 16, 2019 15:09
-
-
Save mtvbrianking/a41e11c08ca27675df2f1337f142c5b1 to your computer and use it in GitHub Desktop.
Extend Soap Client
This file contains 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
<?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