Comments and help on web development.
30  08 2008

Server-side SOAP debugging in PHP

Debugging SOAP in PHP can be really time intensive.

I found the best practice debugging SOAP is using a log file. I use this code to catch exceptions in the server implementation:

$logfilePath = '/path/to/your/logfile.txt'; $debug = true; require_once('Zend/Log.php'); require_once('Zend/Log/Writer/Stream.php'); $writer = new Zend_Log_Writer_Stream(fopen($logfilePath, 'a', false)); $logger = new Zend_Log($writer); try { require_once('MySoapClass.php'); if ($debug) { ini_set("soap.wsdl_cache_enabled", "0"); } $server = new SoapServer($wsdl_url); $server->setClass('MySoapClass'); $server->handle(); } catch (Exception $exception) { if ($debug) { $logger->err($exception); } throw new SoapFault('MySoapServer', $exception); }

I’m using Zend_Log for the logging part, but you should get the idea.

For faster feedback I’m tailing the logfile (tail -f /path/to/your/logfile.txt) and use my usual SOAP client to do the requests.

This debugging technique is useful if you get errors like “looks like we got no XML document” on the client side.

How do you debug server-side SOAP code?

Leave a Reply

« »