I run PHP-FPM with Nginx. I have a variety of different scripts on my servers. Sometimes, there's a problem with PHP codes and the process takes too long. This consumes all available PHP-FPM childs; thus, hinders other php scripts.
How can I set the PHP-FPM log to record slow php processes, as we monitor slow mysql queries, to detect which script is causing problem?
As PHP-FPM receives a proxied connection, a free PHP-FPM worker accepts the web server's request. PHP-FPM then compiles and executes the PHP script, sending the output back to the web server. Once a PHP-FPM worker finishes handling a request, the system releases the worker and waits for new requests.
php-fpm support slow logging feature of php script
in your php-fpm.conf you need to add 2 variable
request_slowlog_timeout and slowlog
according to php-fpm wiki
; The timeout for serving a single request after which a PHP backtrace will be ; dumped to the 'slowlog' file. A value of '0s' means 'off'. ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) ; Default Value: 0
request_slowlog_timeout = 30
; The log file for slow requests ; Default Value: not set ; Note: slowlog is mandatory if request_slowlog_timeout is set
slowlog = log/$pool.log.slow
to monitor mysql queries i am using this query to get the list of queries that are being run on my machine
show full processlist;
This is the second time today when I get to recommend RPM
This is an application performance monitoring tool. Initially, it was a killer app for Rails, but later they started supporting PHP.
It can monitor your scripts, track slow ones, display all kinds of charts.
It also takes care of slow SQL (and you can even see explain plans from within the tool!)
You should definitely check it out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With