When WordPress is a blank site, the opening speed is usually not a problem, as the site becomes richer and richer, more and more plug-ins are installed, the site may become slower and slower to open, what causes WordPress to become slower and slower? Database? Plug-ins? Themes? When encountering technical problems, we can not rely on speculation to locate the problem, for the WordPress site, we can open the PHP slow log slow log to troubleshooting, to see what causes WordPress to slow down.
Enabling slow logging in LNMP environments
The LNMP environment referred to here is through the https://lnmp.org/ Configured environment.
1. Edit the PHP FPM configuration file to enable slow logging
vi /usr/local/php/etc/php-fpm.conf
2. Add the following configuration
request_slowlog_timeout = 2s
slowlog = /var/log/php-slow.log
3. Restart the PHP FPM service
lnmp php-fpm restart
If you have another version of PHP installed, you need to change the configuration file of the PHP site your WordPress site uses to enable slow logging.
Enabling PHP slow logging in cPanel
1. First, log in to the cPanel server via SSH and run the following command to create a configuration file.
mkdir /var/cpanel/ApachePHPFPM/
touch /var/cpanel/ApachePHPFPM/system_pool_defaults.yaml
2. Then add the following configuration items to the system_pool_defaults.yaml file.
---
_is_present: 1
slowlog: { name: 'slowlog', value: "/var/log/php-slow.log" }
request_slowlog_timeout: { name: 'request_slowlog_timeout', value: 1 }
3, rebuild the PHP FPM configuration and restart the PHP FPM service
/usr/local/cpanel/scripts/php_fpm_config --rebuild && /scripts/restartsrv_apache_php_fpm --status
Locating problems with slow logs
After turning on the slow log, we then open the site and refresh it a few times to see something in the slow log, such as the log below:
[05-Nov-2024 23:25:45] [pool sample_com] pid 101088
script_filename = /home/sample/public_html/wp-admin/edit.php
[0x00007f38ea017b60] stream_socket_client() /home/sample/public_html/wp-includes/Requests/src/Transport/Fsockopen.php:173
[0x00007f38ea0166f0] request() /home/sample/public_html/wp-includes/Requests/src/Requests.php:469
[0x00007f38ea0165f0] request() /home/sample/public_html/wp-includes/class-wp-http.php:397
[0x00007f38ea016460] request() /home/sample/public_html/wp-includes/class-wp-http.php:638
[0x00007f38ea0163c0] get() /home/sample/public_html/wp-includes/http.php:184
[0x00007f38ea016330] wp_remote_get() /home/sample/public_html/wp-content/plugins/woocommerce-advanced-product-labels/includes/admin/ class-wapl-hook-check.php:126
[0x00007f38ea016280] _do_hook_check() /home/sample/public_html/wp-content/plugins/woocommerce-advanced-product-labels/includes/admin /class-wapl-hook-check.php:87
[0x00007f38ea0161e0] missing_hook_notice() /home/sample/public_html/wp-includes/class-wp-hook.php:324
[0x00007f38ea016100] apply_filters() /home/sample/public_html/wp-includes/class-wp-hook.php:348
[0x00007f38ea016090] do_action() /home/sample/public_html/wp-includes/plugin.php:517
[0x00007f38ea015fb0] do_action() /home/sample/public_html/wp-admin/admin-header.php:303
[0x00007f38ea0153f0] [INCLUDE_OR_EVAL]() /home/sample/public_html/wp-admin/edit.php:411
WordPress performance optimization has some experience of friends is not difficult to see, WordPress site requests an external URL, and the slow response time of this external URL affects the WordPress open speed. Know the reason, we targeted to solve the problem on the line.
Although this article is for WordPress tutorials, but the principle of which is also suitable for other PHP programs, if your site has encountered the problem of slow opening speed, you may wish to refer to the way to try in this article.
By the way, we also offer a special program for theWordPress Performance Optimization ServicesIf your WordPress site opens slowly, you can entrust us to help you optimize it, for details, please consult the right side of the site WeChat.