PHP SoapClient() gives error 500 and cannot catch the error

Went to an error 500 in production server while using PHP SoapClient library to connect to some third-party API. The error was really strange, just error 500 and nothing more, even if you are using try catch, you won’t be able to catch and see the error.

The Example:


try{
    $client = new SoapClient("https://api.thirdparty.com/some/service?wsdl", ['exceptions' => true, 'trace' => true]);
} catch(SoapFault $fault) {
    trigger_error("SOAP Fault: (faultcode: " . $fault->faultcode . ", faultstring: " . $fault->faultstring . ")", E_USER_ERROR);
} catch(Exception $e) {
    trigger_error("SOAP Error: " . $e->getMessage(), E_USER_ERROR);
}

Even with this, the error 500 will appear and won’t be caught.

The problem of the SoapClient is that his temporary files are messed up somehow, maybe the PHP version was upgraded or maybe the /tmp dir was full on production and the server was not able to create new ones but yes, this is the problem.

So, the solution is simple, just delete all files from /tmp directory on the server that are starting with “wsdl-“ and the error will disappear.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.