PHP-FPM Restart Necessary for Site Speed

celiac101

Well-Known Member
Dec 19, 2012
85
1
8
cPanel Access Level
Website Owner
I have 2 main issues that seem to be dogging me with regard to the site speed on a large php forum.

1) I've done everything I can think of to speed the site up, however, there is still an issue where I need to restart PHP-FPM for it to load quickly. I've tried multiple settings for this
/var/cpanel/userdata/user/mysite.com.php-fpm.yaml
and every other setting I can think of, however, the best way for my site speed to improve is to restart PHP-FPM, then it works like a charm.

I've read many forums and comments about this, and it seems to be a general issue with PHP-FPM. I am considering a cron job that just restarts it every half hour. Others try to steer me to use Litespeed, but I've tried that and wasn't too impressed.

2) Swapping. I've seen multiple posts on forums that blame any memory swapping with server configuration. What I've found is that during the night when my server backs up things like sites and databases, the swapping starts, and once it begins there is a continuous swap that will keep growing over time. Each morning I clear the swap:
swapoff -a && swapon -a
and then no swapping will occur all day long, even when things are very busy on the server. A cron here also comes to mind, as clearing the swap does increase my site speed. Is there a better way to handle this, or is a cron the best way?
 

sparek-3

Well-Known Member
Aug 10, 2002
1,929
178
343
cPanel Access Level
Root Administrator
Are you using Opcache?

That's what this sounds like to me - although others might chime in with other ideas.

With opcache your PHP code is compiled and left in memory for faster loading.

It sounds like your opcache might be filling up with other data and that's why the website loads slow. Restarting php-fpm allows the opcache to empty and rebuild.

This might be a case where file-based opcache would be helpful, and give you better control over what is being cached. There's a feature request for this some where on the feature request site. But it's stuck in feature request purgatory so I wouldn't expect to see it be implemented anytime this century.
 

celiac101

Well-Known Member
Dec 19, 2012
85
1
8
cPanel Access Level
Website Owner
Thank you for the reply. I used to use PHP 7.1 and Memcache, but it isn't supported in PHP 7.3 so I now use Redis, as my forum app has built in support for it.

Regarding my problem #1, I just found what I think is the best solution and am testing it now. It comes from:
PHP5-FPM static, dynamic or on demand?

I use PHP-FPM Ondemand, and just added this to my php-fpm.yaml file:
emergency_restart_threshold = 5
emergency_restart_interval = 1m
process_control_timeout = 10s

So far it is working well, but only time will tell if this solves the issue.

Any help with #2 and the swap issue would be helpful. For example, I am having trouble getting a cron job to work using:
swapoff -a && swapon -a
 

cPanelLauren

Forums Analyst II
Staff member
Nov 14, 2017
8,110
660
263
Houston
cPanel Access Level
DataCenter Provider
Is there anything of note in the PHP-FPM error logs?

Code:
/opt/cpanel/ea-phpXX/root/usr/var/log/php-fpm/error.log
For reference on that feature request, it can be found here: Enable file-based OpCache for PHP 7.0/7.1

As far as using OPcache in conjunction with redis - they're really not meant to be used in conjunction with each other though they do function differently the end goal is essentially the same.

There's some really great discussion on this here:
Redis as a user cache like apcu or opcache? I am so confused
Redis vs APCu 2018
 
Last edited:

celiac101

Well-Known Member
Dec 19, 2012
85
1
8
cPanel Access Level
Website Owner
I see nothing of note in the error log...before I did this lots of this stuff, likely from when I was manually restarting it to speed things up:
[01-Apr-2019 18:26:47] NOTICE: fpm is running, pid 21233
[01-Apr-2019 18:26:47] NOTICE: ready to handle connections
[01-Apr-2019 18:26:47] NOTICE: systemd monitor interval set to 10000ms
[01-Apr-2019 20:49:12] NOTICE: Terminating ...
[01-Apr-2019 20:49:12] NOTICE: exiting, bye-bye!
[01-Apr-2019 20:49:12] NOTICE: fpm is running, pid 27339
[01-Apr-2019 20:49:12] NOTICE: ready to handle connections
[01-Apr-2019 20:49:12] NOTICE: systemd monitor interval set to 10000ms
[02-Apr-2019 04:26:27] NOTICE: Terminating ...
[02-Apr-2019 04:26:27] NOTICE: exiting, bye-bye!

And after the update I just mention, now I see lots of this:
[03-Apr-2019 10:41:21] NOTICE: [pool celiac_com] child 30989 exited with code 0 after 10.799819 seconds from start
[03-Apr-2019 10:41:21] NOTICE: [pool celiac_com] child 30990 started
[03-Apr-2019 10:41:28] NOTICE: [pool celiac_com] child 30987 exited with code 0 after 18.164710 seconds from start
[03-Apr-2019 10:41:28] NOTICE: [pool celiac_com] child 30997 started
[03-Apr-2019 10:41:29] NOTICE: [pool celiac_com] child 30986 exited with code 0 after 19.327120 seconds from start
[03-Apr-2019 10:41:29] NOTICE: [pool celiac_com] child 30998 started

I did see this line from today when I fist restarted it after adding that info, so I will raise this:
[03-Apr-2019 10:41:12] WARNING: [pool celiac_com] server reached max_children setting (5), consider raising it
 

celiac101

Well-Known Member
Dec 19, 2012
85
1
8
cPanel Access Level
Website Owner
I have this at 800 now, and am still getting this warning. I've heard if it is too high it can cause server stability issues:
[03-Apr-2019 10:41:12] WARNING: [pool celiac_com] server reached max_children setting (5), consider raising it
 

cPanelLauren

Forums Analyst II
Staff member
Nov 14, 2017
8,110
660
263
Houston
cPanel Access Level
DataCenter Provider
Hi @celiac101

Too high could cause issues but too low also will cause some issues as you're seeing now, I can't tell you what to set it to but it does sound like you need to increase the max_children for this 5 is actually going to be a bit low for an active site.

Moderation Notice: Posts related to PHP-FPM configuration instructions were moved to a new thread: Modify PHP-FPM Configuration Directives in EasyApache 4
 
Last edited by a moderator: