Googlebot
Googlebot

Reputation: 15673

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?

Upvotes: 5

Views: 16719

Answers (5)

fotuzlab
fotuzlab

Reputation: 1456

Appgati might be of some help here.

It is not an out-an-out solution to your problem, but can provide some useful insights into where the lag has been introduced. You might be having data loss, or losing time in generating the DOM. This script gives sky view of potential areas of concern which can then be specifically targeted.

It can also come handy in finding the performance of a particular function in the script.

Sample output:

Array
(
[Clock time in seconds] => 1.9502429962158
[Time taken in User Mode in seconds] => 0.632039
[Time taken in System Mode in seconds] => 0.024001
[Total time taken in Kernel in seconds] => 0.65604
[Memory limit in MB] => 128
[Memory usage in MB] => 18.237907409668
[Peak memory usage in MB] => 19.579357147217
[Average server load in last minute] => 0.47
[Maximum resident shared size in KB] => 44900
[Integral shared memory size] => 0
[Integral unshared data size] => 0
[Integral unshared stack size] => 
[Number of page reclaims] => 12102
[Number of page faults] => 6
[Number of block input operations] => 192
[Number of block output operations] => 
[Number of messages sent] => 0
[Number of messages received] => 0
[Number of signals received] => 0
[Number of voluntary context switches] => 606
[Number of involuntary context switches] => 99

)

Upvotes: 1

khizar ansari
khizar ansari

Reputation: 1556

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;

Upvotes: 7

symcbean
symcbean

Reputation: 48357

How can I set the PHP-FPM log

No. Use the nginx log_format to record the duration of each HTTP request with millisecond accuracy.

as we monitor slow mysql queries

So you're already stripping out literal values and prioritizing based on the product of frequency and elapsed time?

Upvotes: 3

Stephane Gosselin
Stephane Gosselin

Reputation: 9148

I have been using this class to profile and moniter my own utility scripts. It works fine, if you have nothing against Pear classes.

You can set different timers in the code and act upon the values those timers return. As a bonus, you can have a text or html profiling output of how long it takes for each timer to run.

See the docs for more info.

Hope that helps, good-luck.

Upvotes: 1

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230286

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.

Upvotes: 4

Related Questions