Can I use Zend_Log to handle PHP errors?

I am developing a web service with Zend, and more specifically I am Zend_Amf for interacting with Adobe Flex. The problem is that I cannot easily see PHP errors because the Flex debugger will not display actual responses from the server if they are not proper Amf. If I am at the endpoint of Zend_Amf using a web browser, I get no errors, so there is an error executing the Amf handler. Right now I am using firebug to check HTTP traffic to see any errors.

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

+4
source share
2 answers

you can use set_error_handler to catch PHP errors and use Zend_Log to register them at your discretion.

The only problem with this function is not to catch all the PHP errors, it is impossible to catch errors such as syntax errors ....

Another method is to play with register_shutdown_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 is worth noting that even combining both methods, it will not catch all errors, such as syntax errors .... But you could see such an error using a normal browser.

+2
source

I am not sure my decision will help you here. But if the application terminated due to an exception being thrown, and the errorController error is triggered by default. Then you can take a look at http://blog.elinkmedia.net.au/2009/10/23/application-logging-with-zend_log/

I basically registered a logger instance at boot time and used it to log errors in the error controller.

0
source

Source: https://habr.com/ru/post/1300153/


All Articles