FPM: Difference between revisions

From DWIKI
(16 intermediate revisions by the same user not shown)
Line 7: Line 7:
*[https://www.digitalocean.com/community/tutorials/how-to-configure-apache-http-with-mpm-event-and-php-fpm-on-ubuntu-18-04 Switching to FPM on Ubuntu/Debian]
*[https://www.digitalocean.com/community/tutorials/how-to-configure-apache-http-with-mpm-event-and-php-fpm-on-ubuntu-18-04 Switching to FPM on Ubuntu/Debian]


=Tuning php-fpm =
==Links==
*[https://spot13.com/pmcalculator/ php-fpm settings calculator]
*[https://tideways.com/profiler/blog/an-introduction-to-php-fpm-tuning An Introduction to PHP-FPM Tuning]
==Settings==
===pm.max_children===
Rather complex, maybe have it larger than start_servers + max_spare_servers?


=Monitoring PHP-FPM=
=Monitoring PHP-FPM=
Line 12: Line 20:
*[https://www.zabbix.com/integrations/phpfpm Zabbix monitoring php-fpm]
*[https://www.zabbix.com/integrations/phpfpm Zabbix monitoring php-fpm]
*[https://github.com/jizhang/zabbix-templates/tree/master/php-fpm zabbix php fpm]
*[https://github.com/jizhang/zabbix-templates/tree/master/php-fpm zabbix php fpm]
*[https://www.icdsoft.com/en/kb/view/2053_php_fpm_status fpm status]
==Metrics==
===listen queue===
===max listen queue===
===listen queue len===
===idle processes===
===active processes===
===total processes===
===max active processes===
===max children reached===
===slow requests===
==fpm configuration==
pm.status_listen = 127.0.0.1:9001
pm.status = /fpm-status
pm.ping = /fpm-ping
==Apache==
# I suppose you don't really have to use separate port for this, but might avoid problems
Listen 127.0.0.1:89
<Virtualhost 127.0.0.1:89>
  <Location /fpm-status>
    Require host localhost
    ProxyPass unix:/run/php/php-fpm.sock|fcgi://localhost:9001
  </Location>
  <Location /fpm-ping>
    Require host localhost
    ProxyPass unix:/run/php/php-fpm.sock|fcgi://localhost:9001
  </Location>
</VirtualHost>


=HOWTO=
=HOWTO=
==Configuring number of servers==
==Configuring number of servers==
*[https://tideways.com/profiler/blog/an-introduction-to-php-fpm-tuning An Introduction to PHP-FPM Tuning]
   dynamic - the number of child processes are set dynamically based on the
   dynamic - the number of child processes are set dynamically based on the
             following directives:
             following directives:
             pm.max_children      - the maximum number of children that can
             pm.max_children      - the maximum number of children that can
                                     be alive at the same time.
                                     be alive at the same time. Has to be at least as high as pm.max_spare_servers


             pm.start_servers    - the number of children created on startup.
             pm.start_servers    - the number of children created on startup.
                                     this value must not be less than min_spare_servers  
                                     this value must not be less than min_spare_servers  
                                     and not greater than max_spare_servers.
                                     and not greater than max_spare_servers.
                                    ; Default Value: (min_spare_servers + max_spare_servers) / 2


             pm.min_spare_servers - the minimum number of children in 'idle'
             pm.min_spare_servers - the minimum number of children in 'idle'
Line 33: Line 77:
                                     of 'idle' processes is greater than this
                                     of 'idle' processes is greater than this
                                     number then some children will be killed.
                                     number then some children will be killed.
=FAQ=
=FAQ=
==[pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers)==
==error messages==
===pm.min_spare_servers(3) and pm.max_spare_servers(7) cannot be greater than pm.max_children(5)===
Obviously, pm.max_children has to be at least as high as pm.max_spare_servers
==proxy_fcgi AH01071: Got error 'Primary script unknown'==
==proxy_fcgi AH01071: Got error 'Primary script unknown'==
The fcgi 404
The fcgi 404, so you're requesting a nonexisting link
 


==AH01079: failed to make connection to backend: httpd-UDS==
==AH01079: failed to make connection to backend: httpd-UDS==
USB = Unix Domain Socket, look for logging/config about the socket involved
USB = Unix Domain Socket, look for logging/config about the socket involved
==WARNING: [pool www] ACL set, listen.owner = 'apache' is ignored==
Redhat feature, check commenting out acl_users in www.conf
==AH01144: No protocol handler was valid for the URL /fpm-ping (scheme 'fcgi'). ==
If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.
a2enmod proxy_fcgi


==Show php-fpm config==
==Show php-fpm config==
  php-fpm8.0 -tt
  php-fpm8.0 -tt
==server reached pm.max_children setting==

Revision as of 10:41, 5 February 2025

FastCGI Process Manager

Links

Tuning php-fpm

Links

Settings

pm.max_children

Rather complex, maybe have it larger than start_servers + max_spare_servers?

Monitoring PHP-FPM

Metrics

listen queue

max listen queue

listen queue len

idle processes

active processes

total processes

max active processes

max children reached

slow requests

fpm configuration

pm.status_listen = 127.0.0.1:9001
pm.status = /fpm-status
pm.ping = /fpm-ping

Apache

  1. I suppose you don't really have to use separate port for this, but might avoid problems
Listen 127.0.0.1:89
<Virtualhost 127.0.0.1:89>
 <Location /fpm-status>
   Require host localhost
   ProxyPass unix:/run/php/php-fpm.sock|fcgi://localhost:9001
 </Location>
 <Location /fpm-ping>
   Require host localhost
   ProxyPass unix:/run/php/php-fpm.sock|fcgi://localhost:9001
 </Location>
</VirtualHost>

HOWTO

Configuring number of servers

  dynamic - the number of child processes are set dynamically based on the
            following directives:
            pm.max_children      - the maximum number of children that can
                                   be alive at the same time. Has to be at least as high as pm.max_spare_servers
            pm.start_servers     - the number of children created on startup.
                                   this value must not be less than min_spare_servers 
                                   and not greater than max_spare_servers.
                                   ; Default Value: (min_spare_servers + max_spare_servers) / 2
            pm.min_spare_servers - the minimum number of children in 'idle'
                                   state (waiting to process). If the number
                                   of 'idle' processes is less than this
                                   number then some children will be created.
            pm.max_spare_servers - the maximum number of children in 'idle'
                                   state (waiting to process). If the number
                                   of 'idle' processes is greater than this
                                   number then some children will be killed.

FAQ

[pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers)

error messages

pm.min_spare_servers(3) and pm.max_spare_servers(7) cannot be greater than pm.max_children(5)

Obviously, pm.max_children has to be at least as high as pm.max_spare_servers

proxy_fcgi AH01071: Got error 'Primary script unknown'

The fcgi 404, so you're requesting a nonexisting link

AH01079: failed to make connection to backend: httpd-UDS

USB = Unix Domain Socket, look for logging/config about the socket involved


WARNING: [pool www] ACL set, listen.owner = 'apache' is ignored

Redhat feature, check commenting out acl_users in www.conf

AH01144: No protocol handler was valid for the URL /fpm-ping (scheme 'fcgi').

If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.

a2enmod proxy_fcgi

Show php-fpm config

php-fpm8.0 -tt


server reached pm.max_children setting