Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to monitor slow PHP processes?

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?

like image 473
Googlebot Avatar asked Dec 19 '11 11:12

Googlebot


People also ask

How does PHP-FPM work?

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.


2 Answers

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;
like image 116
khizar ansari Avatar answered Oct 01 '22 05:10

khizar ansari


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.

like image 24
Sergio Tulentsev Avatar answered Oct 01 '22 07:10

Sergio Tulentsev