===== PHP =====
==== Репозиторий для Debian ====
#!/bin/sh
# To add this repository please do:
if [ "$(whoami)" != "root" ]; then
SUDO=sudo
fi
${SUDO} apt-get update
${SUDO} apt-get -y install lsb-release ca-certificates curl
${SUDO} curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg
${SUDO} sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
${SUDO} apt-get update
https://packages.sury.org/php/README.txt
==== Файл phpinfo ====
Для вывода информации о PHP через браузер
==== server reached pm.max_children setting ====
Веб-сервер перестаёт отвечать, потом опять работает. В логах:
tail /var/log/php8.1-fpm.log
[03-Aug-2021 18:57:39] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 0 idle, and 13 total children
[03-Aug-2021 22:01:32] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 0 idle, and 16 total children
[03-Aug-2021 22:01:33] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 16 children, there are 0 idle, and 17 total children
[03-Aug-2021 22:01:52] WARNING: [pool www] server reached pm.max_children setting (20), consider raising it
[04-Aug-2021 09:32:25] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 0 idle, and 19 total children
[04-Aug-2021 09:32:26] WARNING: [pool www] server reached pm.max_children setting (20), consider raising it
[04-Aug-2021 10:41:00] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 0 idle, and 16 total children
[04-Aug-2021 10:41:01] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 16 children, there are 0 idle, and 17 total children
[04-Aug-2021 10:41:21] WARNING: [pool www] server reached pm.max_children setting (20), consider raising it
[04-Aug-2021 10:51:58] WARNING: [pool www] server reached pm.max_children setting (20), consider raising it
Чтобы заранее предупредить ошибку\\
[pool www] pm.start_servers(20) must not be less than pm.min_spare_servers(1) and not greater than pm.max_spare_servers(10),\\
необходимо
* Посмотреть (top), какая версия php-fpm работает, и править соотв. конфиг
* Значение **pm.start_servers** установить в 2 раза больше кол-ва ядер процессора
* **pm.max_spare_servers** установить в 2 раза больше **pm.start_servers**
* **pm.max_children** вычислить от кол-ва памяти, разделённого на объём одного потока, например, 16000 / 70 ≈ 200
* **pm.max_requests** ограничить, например, 500
Объём потока (RSS, это в килобайтах), т. е., примерно 70 МБ.
root@vmls-www1:~# ps -ylC php-fpm8.1 --sort:rss -u www-data
S UID PID PPID C PRI NI RSS SZ WCHAN TTY TIME CMD
S 33 1059 828 0 80 0 68164 68113 skb_wa ? 00:00:03 php-fpm8.1
S 33 1055 828 0 80 0 68984 68042 skb_wa ? 00:00:03 php-fpm8.1
S 33 1056 828 0 80 0 69056 68015 skb_wa ? 00:00:03 php-fpm8.1
# Выяснить текущие значения
cat /etc/php/8.1/fpm/pool.d/www.conf |egrep '^pm.max_children|^pm.start_servers|^pm.max_spare_servers|^pm.max_requests'
pm.max_children = 7
pm.start_servers = 2
pm.max_spare_servers = 3
;pm.max_requests = 500
sed -i '
/pm.max_children =/c pm.max_children = 200
/pm.start_servers =/c pm.start_servers = 16
/pm.max_spare_servers =/c pm.max_spare_servers = 32
/pm.max_requests =/c pm.max_requests = 500' /etc/php/8.1/fpm/pool.d/www.conf
https://stackoverflow.com/questions/25097179/warning-pool-www-seems-busy-you-may-need-to-increase-pm-start-servers-or-pm\\
https://habr.com/ru/companies/slurm/articles/460511/
==== Включить логи в докере ====
Стандартно логи в STDOUT/STDERR не пишутся. Чтобы включить для php-fpm, нужно создать файл
[global]
error_log = /proc/self/fd/2
[www]
access.log = /proc/self/fd/2
catch_workers_output = yes
decorate_workers_output = no
https://mateuszcholewka.com/post/php-logs-in-docker/