Question

I'm developing a project using Symfony 2.1.

I have created a service that is being called from a controller, and it's working ok. Now I need that the service generates log, and I'm trying to pass logger this way:

soap.client:
    class: MyFirm\MyAppBundle\Service\SOAPClient
        arguments: 
            logger: "@logger"

My service is defined this way:

namespace MyFirm\MyAppBundle\Service;

use \SoapClient as SoapClient;

use Monolog\Logger;

class SOAPClient
{
    private $logger;

    function __construct (Logger $logger)
    {
        $this->logger = $logger;
    }

    function sendMessage ($message, $wsdl_url) 
    {
        $webServResult = "ERROR";

        try{
            $client = new SoapClient($wsdl_url, array("trace"=>true,
                    "exceptions"=>true));        
            $webServResult=$client->sendMessage($data);
        }
        catch(\Exception $ex){
            $webServResult="ERROR";
            $message=$ex->getMessage();
            $log_text = print_r($ex, true)."\n".
                    $client->__getLastRequest()."\n".
                    $client->__getLastResponse();
            $this->logger->err("ERROR: ".$log_text);            
        }               

        return $webServResult;
    }


}

However, when I use the logger (if the wsdl doesn't exist, for example), the application hangs.

Am I doing anything wrong? Thanks a lot.

Was it helpful?

Solution 2

Sorry, the problem wasn't at logger, but in the lines:

  $log_text = print_r($ex, true)."\n".
                $client->__getLastRequest()."\n".
                $client->__getLastResponse();

If I remove these lines and log only the Exception message all goes right. SoapClient does generate an Exception if the WSDL is not found:

SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://localhost/unknown.wsdl' : 
             failed to load external entity "http://localhost/unknown.wsdl"

Solved and fixed. Sorry for the spam.

OTHER TIPS

This is not a problzm from logger but from SoapClient that doesn't throw any Exception in case of unreachable WSDL... It waits until a Fatal error is thrown...

You have to check if WSDl exists before calling SoapClient ;)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top