[30-Jul-2014 05:38:50] WARNING: [pool www] child 11606 said into stderr: "NOTICE: PHP message: PHP Fatal error: Uncaught exception'Zend_View_Exception' with message'script'new-layout .mobile.phtml' not found...."
[30-Jul-2014 05:38:50] WARNING: [pool www] child 11606 said into stderr: "Stack trace:"
[ 30-Jul-2014 05:38:50] WARNING: [pool www] child 11606 said into stderr: "#0 /usr/share/nginx/html/site.com/142-webapp/library/Zend/View/Abstract .php(884): Zend_View_Abstract->_script('new-layout.mobi...')"
[30-Jul-2014 05:38:50] WARNING: [pool www] child 11606 said into stderr : "#1 /usr/share/nginx/html/site.com/142-webapp/library/Zend/Layout.php(796): Zend_View_Abstract->render('new-layout.mobi...')"< br />[30-Jul-2014 05:38:50] WARNING: [pool www] child 11606 said into stderr: "#2 /usr/share/nginx/html/site.com/142-webapp/library/Zend /Layout/Controller/Plugin/Layout.php(143): Zend _Layout->render()"
[30-Jul-2014 05:38:50] WARNING: [pool www] child 11606 said into stderr: "#3 /usr/share/nginx/html/site.com /142-webapp/library/Zend/Controller/Plugin/Broker...."
As you can see, each line of the stack trace is actually a separate event with its own timestamp. There is a problem when logs are forwarded to another service for analysis, because when each stack trace should be treated as an event, they will be broken down. Currently I am using Kibana 3, which is a nightmare to view and manage stack traces, Because each line is a separate event, and the events are not always arranged in chronological order.
How to make php-fpm register each stack trace as an event?
PHP-FPM just divides each line PHP output is recorded as a separate event. In PHP-FPM you cannot do anything to change it.
PHP code
You need to fix this problem in your application (PHP Code). There are three ways to influence the way PHP reports errors, you may want to use all 3:
>Use set_error_handler()
to register a custom error handler. Except E_ERROR , E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and most of the E_STRICT raised in the file where set_error_handler() is called, this handler will be called.
>Use set_exception_handler()
to register a custom exception Handler. This handler will be called when an uncaught exception occurs.
>Use register_shutdown_function()
to register a custom shutdown function. This is called after the script execution is complete or exit() is called Function. This is used to detect unhandled errors by the error handler.
Log library
I can suggest you to take a look at Monolog. This is a PSR-3 complaint logging library, and it also has Help me what I described above.
In addition, it also has an impressive list of “handlers” that can write logs to various services. The service you are currently using is likely to be in!
Replacement
Another option is to create a proxy script that will read the PHP-FPM log file and buffer the lines until the “complete event” is collected. Then it Write as a single entry to the service you are using.
I suggest you don’t go this way. Writing such scripts can be tricky and very error-prone. Logging from your application itself is more stable and reliable.
I have a question, PHP-FPM registers a single event as multiple events. Take the following stack trace as an example:
[30-Jul-2014 05:38:50] WARNING: [pool www] child 11606 said into stderr: "NOTICE: PHP message: PHP Fatal error: Uncaught exception'Zend_View_Exception' with message'script 'new-layout.mobile.phtml' not found...."
[30-Jul-2014 05:38:50] WARNING: [pool www] child 11606 said into stderr: "Stack trace:"< br />[30-Jul-2014 05:38:50] WARNING: [pool www] child 11606 said into stderr: "#0 /usr/share/nginx/html/site.com/142-webapp/library/Zend /View/Abstract.php(884): Zend_View_Abstract->_script('new-layout.mobi...')"
[30-Jul-2014 05:38:50] WARNING: [pool www] child 11606 said into stderr: "#1 /usr/share/nginx/html/site.com/142-webapp/library/Zend/Layout.php(796): Zend_View_Abstract->render('new-layout.mobi... ')"
[30-Jul-2014 05:38:50] WARNING: [pool w ww] child 11606 said into stderr: "#2 /usr/share/nginx/html/site.com/142-webapp/library/Zend/Layout/Controller/Plugin/Layout.php(143): Zend_Layout->render( )"
[30-Jul-2014 05:38:50] WARNING: [pool www] child 11606 said into stderr: "#3 /usr/share/nginx/html/site.com/142-webapp/ library/Zend/Controller/Plugin/Broker...."
As you can see, each line of the stack trace is actually a separate event with its own timestamp. Forward the log to another There will be problems when the service performs analysis, because when each stack trace should be treated as an event, they will be broken down. Currently I am using Kibana 3, which is a nightmare to view and manage stack traces because each line is A separate event, and each event is not always arranged in chronological order.
How to make php-fpm register each stack trace as an event?
Unfortunately
PHP-FPM just records each line of PHP output as a separate event. In PHP- You can’t do anything in FPM to change it.
PHP code
You need to fix this problem in your application (PHP code). There are three ways to affect PHP reporting errors Way, you may want to use all 3:
>Use set_error_handler()
to register a custom error handler. Except for E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING and calling In addition to most E_STRICT raised in the file of set_error_handler(), this handler will be called.
>Use set_exception_handler()
to register a custom exception handler. When an uncaught exception occurs, it will Call this handler.
>Use register_shutdown_function()
to register a custom shutdown function. This function is called after the script execution is completed or exit() is called. This is used to detect the unprocessed error handler Error.
Log library
I can suggest you to take a look at Monolog. This is a PSR-3 complaint logging library, and it also helps what I described above.
In addition, it also has an impressive list of “handlers” that can write logs to various services. The service you are using now is likely to be among them!
Replacement
Another option is to create a proxy script that will read the PHP-FPM log file and buffer the lines until the “complete event” is collected. Then it Write as a single entry to the service you are using.
I suggest you don’t go this way. Writing such scripts can be tricky and very error-prone. Logging from your application itself is more stable and reliable.