Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logging all Soap request and responses in PHP

Tags:

php

soap

Does anyone know how to log all request and responses with the builtin SoapClient in PHP? I could in fact manually log everything with SoapClient::__getLastRequest() and SoapClient::__getLastResponse() But we have that much soap requests in our system that i'm looking other possibilities.

Note: i'm using wsdl mode so using a method that tunnels all through to SoapClient::__soapCall() isn't an option

like image 919
ChrisR Avatar asked Nov 13 '09 13:11

ChrisR


1 Answers

I think the better way is to override SoapClient::__doRequest() (and not SoapClient::__soapCall()) as you'll have direct access to the request- as well as to the response-XML. But the general approach to subclass SoapClient should be the way to go.

class My_LoggingSoapClient extends SoapClient
{
    // logging methods

    function __doRequest($request, $location, $action, $version, $one_way = 0) 
    {
        $this->_logRequest($location, $action, $version, $request);
        $response = parent::__doRequest($request, $location, $action, $version, $one_way);
        $this->_logResponse($location, $action, $version, $response);
        return $response;
    }
}

EDIT

From an OOP-design / design pattern point of view a Decorator is obviously the better way to handle this kind of problem - please see Gordon's answer. But this is a little bit more difficult to implement.

like image 148
Stefan Gehrig Avatar answered Sep 28 '22 00:09

Stefan Gehrig