PHP SOAP error catching

后端 未结 7 1336
北恋
北恋 2020-12-14 07:49

I\'m getting desperate, all I want is simple error handling when the PHP SOAP Web Service is down to echo an error message login service down. Please help me!

7条回答
  •  清歌不尽
    2020-12-14 08:15

    Unfortunately SOAP throws a fatal error when the service is down / unreachable rather than returning a SoapFault object.

    That being said, you can set it to throw an exception. You probably omitted the part where you're setting the exceptions soap_client option to false

    $client = new SoapClient("http://192.168.0.142:8080/services/Logon?wsdl",array(
        'exceptions' => false,    // change to true so it will throw an exception
    ));
    

    Catch the exception when service is down:

    try {
      $client = new SoapClient("http://192.168.0.142:8080/services/Logon?wsdl",array(
        'exceptions' => true,
      ));
    }
    catch ( Exception $e )
    {
        echo 'sorry... our service is down';
    }
    

提交回复
热议问题