Daniel Lockyer

PHP Performance: How To Find Slow PHP Scripts


It is important to keep a website fast so users have a good experience. Some pages on your website may be slower than others, possibly due to slow backend code. I use this super simple method to find the slowest loading PHP scripts and fix them.

Remember, you can’t fix what you can’t measure.

In /etc/php/7.2/fpm/pool.d/www.conf, set access.format to something like

%{mili}d %{kilo}M %C%% %{HTTP_HOST}e %f%Q%q

so the time taken to process the request is first. Then you can use a command like the following to find your slowest loading scripts. (I also changed access.log so check where your access logs are being stored. You might need to manually set it.)

tail -n 1000 /var/log/php7.2-fpm.access.log | sort -n

You can then profile the PHP scripts to find the slow sections and fix them to make your website fast.

If you’re looking to fix your site performance, email me at [email protected]!