How to restart php-fpm automatically?

Aar

Verified User
Joined
Feb 10, 2005
Messages
208
Location
Netherlands
Recently I got a new VPS server with 4GB RAM. The server has been running with one of my important sites for a few days now, but suddenly it was unreachable. Soon I noticed that php-fpm had overflowed with 2 GB of processes in memory.

Normally it runs around 110 MB of processes. Does anyone have an idea what could have been going on? I did notice that there is a massive attack on my contact form (which is secured), so I suspect a large amount of requests has knocked my php-fpm down or maybe a memory-leak of another glitch?

Does anyone have a good solution to automatically throw this php-fpm back up when it's down and let me know? or maybe better to set this so that it does not happen or less often?
 
Last edited:
maybe you on php 8.1.5?
FPM:
  • Fixed bug #77023 (FPM cannot shutdown processes).
that solved problem for me, also to prevent memory leaks - tune:
pm.max_children =
pm.process_idle_timeout =
pm.max_requests =
 
I have on this moment PHP 7.3, when my website is ready i will upgrade to 8.1.x
This is my configuration:
listen = /usr/local/php73/sockets/$pool.sock
listen.owner = $pool
listen.group = apache
listen.mode = 660

pm = ondemand
pm.max_children = 10
pm.process_idle_timeout = 60
pm.max_requests = 1000
Where can i find the logs?
I see in the configuration this line:
error_log = log/php-fpm.log
But where can i find the log?

I have more logs, from top. MySQL is using 101.6 % CPU?
How is MySQL hitting my php-fpm?
This is an automated message notifying you that the 5 minute load average on your system is 69.99.
This has exceeded the 10 threshold.

One Minute - 126.25
Five Minutes - 69.99
Fifteen Minutes - 35.8

top - 16:11:33 up 1 day, 22:40, 0 users, load average: 124.31, 70.52, 36.15
Tasks: 356 total, 22 running, 334 sleeping, 0 stopped, 0 zombie
%Cpu(s): 50.3 us, 46.9 sy, 0.0 ni, 0.0 id, 0.0 wa, 1.1 hi, 1.7 si, 0.0 st
MiB Mem : 3736.5 total, 143.9 free, 1316.8 used, 2275.8 buff/cache
MiB Swap: 1024.0 total, 989.0 free, 35.0 used. 2077.0 avail Mem

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
837 mysql 20 0 1619140 264224 23736 S 101.6 6.9 97:16.30 /usr/sbin/mysqld
172056 root 20 0 62632 4836 3924 R 4.7 0.1 0:00.03 /usr/bin/top -c -b -n 1
172062 root 20 0 62632 4848 3932 R 4.7 0.1 0:00.03 /usr/bin/top -c -b -n 1
172064 root 20 0 62632 4816 3908 R 4.7 0.1 0:00.03 /usr/bin/top -c -b -n 1
110601 root 20 0 115532 34888 6552 R 3.1 0.9 1:14.17 lfd - scanning log files
168688 apache 20 0 2298800 51704 10324 S 3.1 1.4 1:14.09 /usr/sbin/httpd -DFOREGROUND
171627 arien 20 0 364152 22744 15924 S 3.1 0.6 0:00.02 php-fpm: pool arien
171745 apache 20 0 2166500 24196 10420 S 3.1 0.6 0:00.65 /usr/sbin/httpd -DFOREGROUND
172042 root 20 0 62632 4812 3904 R 3.1 0.1 0:00.03 /usr/bin/top -c -b -n 1
172058 root 20 0 62632 4784 3864 R 3.1 0.1 0:00.03 /usr/bin/top -c -b -n 1
172093 root 20 0 16608 2584 2328 R 3.1 0.1 0:00.04 /bin/netstat -autpn
172101 root 20 0 62632 4768 3852 R 3.1 0.1 0:00.03 /usr/bin/top -c -b -n 1
9 root 20 0 0 0 0 S 1.6 0.0 0:05.88 [ksoftirqd/0]
56 root 20 0 0 0 0 S 1.6 0.0 0:02.55 [kswapd0]
816 root 20 0 227524 17460 15436 S 1.6 0.5 0:54.94 /usr/libexec/sssd/sssd_nss --uid 0 --gid 0 --logger=files
171146 arien 20 0 417572 31364 24812 R 1.6 0.8 0:00.11 /usr/local/bin/php /home/arien/domains/**********/public_html/******/**********.php
171443 apache 20 0 2167352 25104 10144 S 1.6 0.7 0:01.13 /usr/sbin/httpd -DFOREGROUND
171583 arien 20 0 364152 22996 16168 S 1.6 0.6 0:00.02 php-fpm: pool arien
171653 arien 20 0 364152 22676 15856 S 1.6 0.6 0:00.01 php-fpm: pool arien
171695 arien 20 0 364152 22196 15380 S 1.6 0.6 0:00.01 php-fpm: pool arien
1 root 20 0 172536 10792 8120 S 0.0 0.3 0:29.50 /usr/lib/systemd/systemd --switched-root --system --deserialize 18
2 root 20 0 0 0 0 S 0.0 0.0 0:00.04 [kthreadd]
3 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 [rcu_gp]
 
Last edited:
/usr/local/php73/var/log
or in /var/log/@php-fpm73.log (it is a symlink to /usr/local/php73/var/log)
 
maybe you have high memory limit, or additional modules loaded that can increase memory consumption.
if website don't need them - you can recompile php without them, or disable them to decrease footprint in ram.
 
This is the error:
WARNING: [pool arien] server reached max_children setting (100), consider raising it
I just got a message from my hosting that they were having problems with their underlying VPS architecture, which has since been resolved. Since a value of max_children 100 should be fine, and is the default in DirectAdmin, I'm assuming the underlying issues will be the cause.

And the fact that MySQL had a high CPU would have something to do with that, I suspect.
What do you think of it?
 
Now I no longer experience any problems. ☺️
But do you have any idea where I can find the MariaDB log?

I found this list of log-file locations, but /var/lib/mysql/server.hostname.com.err, doesn't exists om Almalinux (Centos). (offcourse with right hostname)
 
pm.max_children =
I'm just wondering if this setting can cause conflicts or odd things.
Because there are 2 similar values which can be used.

In directadmin.conf there is:
php_fpm_max_children_default=
and in php-fpm.conf it's the above setting.

I've got for example in directadmin.conf a value of 70 and in the php-fpm.conf the default value of 10 I don't really know what's the difference or which setting is overruling (if any).
 
@Zhenyapan Yep I'm aware of that page. But I don't quite understand the difference, which is why I asked.
Or does the directadmin.conf just mean that the limit there, can not be overruled by the ones in the php-fpm.conf files?

The doc is still not very clear, but it doesn't state if this is per php-fpm version or in total.
For example if you have 3 php-fpm versions with max 10 set in php-fpm.conf and directadmin.conf, you would have 30 max, which would be more then the limit in directadmin.conf.
 
The doc is still not very clear, but it doesn't state if this is per php-fpm version or in total.
it's default limit for each php version separately. For example if you provide cheap hosting and want to limit user cpu consumption - you can set default limit 2 children, so even if they will be 100% loaded - it will use only 2 cpu cores. It's the same limit which you can configure per user per each it's php version.
 
@jamgames2 I'm not talking about anything custom. I know you have to do the ./build rewrite_confs after changing the value in directadmin.conf but it doesn't say anything anyway about the /usr/lib/phpXX/etc/php-fpm.conf which has a similar option.

@Zhenyapan So it's like this then?
Directadmin.conf -> Max children for each php-fpm version seperately
/usr/lib/phpXX/etc/php-fpm.conf -> Max children for that specific php-fpm version. So you can set for example 10 for php 7.4 and 4 for php 8.0 but never more then 10 because in directadmin.conf the max limit is 10. So in php-fpm.conf you can't use 11 or more for example.
That correct?

@Aar Weet jij dat toevallig?
 
@Richard G
I meant, it rewrite to these file.
/usr/local/directadmin/data/users/{SOME_USER}/php/php-fpmXX.conf

no need to do with /usr/lib/phpXX/etc/php-fpm.conf

because only have one template to custom php-fpm, maybe that path you mention doesn't make change with php_fpm_max_children_default. I never check that path.
 
Last edited:
I meant, it rewrite to these file.
Ah indeed, it does. That makes it even more confusing to me. What is the /usr/local/phpXX/etc/php-fpm.conf for then?

So it's the other way around? The /usr/local/phpXX/etc/php-fpm.conf is for the default php-fpm settings for that version and directadmin.conf overrules it for all users?
 
Directadmin.conf -> Max children for each php-fpm version seperately
/usr/lib/phpXX/etc/php-fpm.conf -> Max children for that specific php-fpm version. So you can set for example 10 for php 7.4 and 4 for php 8.0 but never more then 10 because in directadmin.conf the max limit is 10. So in php-fpm.conf you can't use 11 or more for example.
That correct?
no, it's start limit which just be put to all configs afrer rewrite_confs or PHP rebuild/update. I think it shouldn't prevent you to increase limit for user/global manually. but better to ask @smtalk
 
Oke thank you both very much.
I will start a seperate thread if I need it and doesn't do what I now think it should do. ;)
 
Back
Top