How to locate the slow access to php programs
The company's business is developed in PHP, so nine times out of ten, the environment used is LNMP. In the daily operation and maintenance work, more than 90% of the faults are performance problems.
You may think, our business is running well, why do we have performance problems for no reason?
There are too many possible reasons, such as code changes, abnormal access, network fluctuations, server hardware failures, and so on.
There are so many reasons for performance problems, how to locate them?
To introduce you to a performance tracking method, this method has been successful in my operation and maintenance career, and has helped me a lot.
-slow log tracking-
We can easily track the problem point through slow log. Let's first look at the configuration method.
1) Edit configuration file
Assume that the php installation path is / usr/local/php, the configuration file path / usr/local/php/etc/php-fpm.conf)
# vim / usr/local/php/etc/php-fpm.conf # change or add two lines slowlog = / data/logs/php-slow.logrequest_slowlog_timeout = 2
Description: slowlog defines the log path and name, request_slowlog_timeout defines the timeout, in seconds, that is, if the execution time of a php script exceeds this time, the log will be recorded.
2) restart the php-fpm service
Specific restart commands are determined according to your own environment. After the configuration file is modified, it will not take effect if you do not restart or reload the service.
3) Test
Create a new test.php file in the test site and write the following: