4

I'm developing a web service with Zend, more specifically I'm Zend_Amf for interop with Adobe Flex. The problem with this is that I can not easily see PHP errors because the Flex debugger won't display the actual answers from the server unless they are proper Amf. If I visit the Zend_Amf endpoint with the Web Browser I don't get any errors, so the error is while executing an Amf handler. Right now I'm using firebug to inspect the HTTP traffic to see any errors.

To my question: can I use a log utility (like Zend_Log) to log all PHP errors, warnings and notices to a file instead of (or in addition to) sending them in a HTTP response?

2 Answers 2

2

you can use set_error_handler to catch PHP errors and use Zend_Log to log them as you please.

The only problem with this function it won't catch all PHP errors, it is not possible to catch errors like syntax errors ....

An other method is to play with the register_shutdown_function function

like this:

error_reporting(E_ALL);
    ini_set('display_errors', 0);

    function shutdown(){
        $isError = false;
        if ($error = error_get_last()){
            switch($error['type']){
                case E_ERROR:
                case E_CORE_ERROR:
                case E_COMPILE_ERROR:
                case E_USER_ERROR:
                    $isError = true;
                    break;
            }
        }

        if ($isError){
            echo "Script execution halted ({$error['message']})";
        } else {
            echo "Script completed";
        }
    }

    register_shutdown_function('shutdown');

It's worth to be noted then even by combining both methods it won't catch all errors, like syntaxes errors .... But you could see that kind of error using a normal browser.

Sign up to request clarification or add additional context in comments.

Comments

0

I'm not sure if my solution will help you here. But if you application terminates because of an exception has been thrown and the default errorController is triggered. Then you may want to have a look at http://blog.elinkmedia.net.au/2009/10/23/application-logging-with-zend_log/

I basically registered a logger instance during bootstrapping, and use it to log errors in the error controller.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.