Logging all Soap request and responses in PHP

前端 未结 6 1128
北荒
北荒 2020-12-09 06:00

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()

6条回答
  •  醉话见心
    2020-12-09 06:22

    Would something like this work?

    class MySoapClient extends SoapClient
    {
        function __soapCall($function_name, $arguments, $options = null, $input_headers = null, &$output_headers = null) 
        {
            $out = parent::__soapCall($function_name, $arguments, $options, $input_headers, $output_headers);
    
            // log request here...
            // log response here...
    
            return $out;
        }
    }
    

    Since SoapClient already sends all requests through __soapCall, you can intercept them by subclassing SoapClient and overriding it. Of course, to make it work you need to also replace every new SoapClient(...) in your code with new MySoapClient(...), but that seems like a pretty easy search and replace task.

提交回复
热议问题