diff options
author | Jérôme Loyet <fat@php.net> | 2011-10-08 13:47:52 +0000 |
---|---|---|
committer | Jérôme Loyet <fat@php.net> | 2011-10-08 13:47:52 +0000 |
commit | c6b633a32afd876414afd3c76510b1e7dee4cfe4 (patch) | |
tree | a996afa0c5dcec684fc08f200f1c4485adc57e3f | |
parent | c4e961f06e08496a8bf91776b8006a1a244176fa (diff) | |
download | php-git-c6b633a32afd876414afd3c76510b1e7dee4cfe4.tar.gz |
- Backported FR #55166 from 5.4 branch (Added process.max to control the number of process FPM can fork)
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | sapi/fpm/fpm/fpm_children.c | 17 | ||||
-rw-r--r-- | sapi/fpm/fpm/fpm_conf.c | 10 | ||||
-rw-r--r-- | sapi/fpm/fpm/fpm_conf.h | 1 | ||||
-rw-r--r-- | sapi/fpm/php-fpm.conf.in | 7 |
5 files changed, 35 insertions, 2 deletions
@@ -75,6 +75,8 @@ PHP NEWS . Fixed bug #53872 (internal corruption of phar). (Hannes) - PHP-FPM SAPI: + . Backported FR #55166 from 5.4 branch (Added process.max to control + the number of process FPM can fork). (fat) . Backported FR #55181 from 5.4 branch (Enhance security by limiting access to user defined extensions). (fat) . Backported FR #54098 from 5.4 branch (Lowered process manager diff --git a/sapi/fpm/fpm/fpm_children.c b/sapi/fpm/fpm/fpm_children.c index 94580194fa..216cf4f033 100644 --- a/sapi/fpm/fpm/fpm_children.c +++ b/sapi/fpm/fpm/fpm_children.c @@ -362,6 +362,7 @@ int fpm_children_make(struct fpm_worker_pool_s *wp, int in_event_loop, int nb_to pid_t pid; struct fpm_child_s *child; int max; + static int warned = 0; if (wp->config->pm == PM_STYLE_DYNAMIC) { if (!in_event_loop) { /* starting */ @@ -373,7 +374,16 @@ int fpm_children_make(struct fpm_worker_pool_s *wp, int in_event_loop, int nb_to max = wp->config->pm_max_children; } - while (fpm_pctl_can_spawn_children() && wp->running_children < max) { + /* + * fork children while: + * - fpm_pctl_can_spawn_children : FPM is running in a NORMAL state (aka not restart, stop or reload) + * - wp->running_children < max : there is less than the max process for the current pool + * - (fpm_global_config.process_max < 1 || fpm_globals.running_children < fpm_global_config.process_max): + * if fpm_global_config.process_max is set, FPM has not fork this number of processes (globaly) + */ + while (fpm_pctl_can_spawn_children() && wp->running_children < max && (fpm_global_config.process_max < 1 || fpm_globals.running_children < fpm_global_config.process_max)) { + + warned = 0; child = fpm_resources_prepare(wp); if (!child) { @@ -406,6 +416,11 @@ int fpm_children_make(struct fpm_worker_pool_s *wp, int in_event_loop, int nb_to } + if (!warned && fpm_global_config.process_max > 0 && fpm_globals.running_children >= fpm_global_config.process_max) { + warned = 1; + zlog(ZLOG_WARNING, "The maximum number of processes has been reached. Please review your configuration and consider raising 'process.max'"); + } + return 1; /* we are done */ } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_conf.c b/sapi/fpm/fpm/fpm_conf.c index 2f28fb9465..edb514f1be 100644 --- a/sapi/fpm/fpm/fpm_conf.c +++ b/sapi/fpm/fpm/fpm_conf.c @@ -66,8 +66,9 @@ static char *fpm_conf_set_syslog_facility(zval *value, void **config, intptr_t o struct fpm_global_config_s fpm_global_config = { .daemonize = 1, #ifdef HAVE_SYSLOG_H - .syslog_facility = -1 + .syslog_facility = -1, #endif + .process_max = 0, }; static struct fpm_worker_pool_s *current_wp = NULL; static int ini_recursion = 0; @@ -79,6 +80,7 @@ static struct ini_value_parser_s ini_fpm_global_options[] = { { "emergency_restart_threshold", &fpm_conf_set_integer, GO(emergency_restart_threshold) }, { "emergency_restart_interval", &fpm_conf_set_time, GO(emergency_restart_interval) }, { "process_control_timeout", &fpm_conf_set_time, GO(process_control_timeout) }, + { "process.max", &fpm_conf_set_integer, GO(process_max) }, { "daemonize", &fpm_conf_set_boolean, GO(daemonize) }, { "pid", &fpm_conf_set_string, GO(pid_file) }, { "error_log", &fpm_conf_set_string, GO(error_log) }, @@ -1014,6 +1016,11 @@ static int fpm_conf_post_process(TSRMLS_D) /* {{{ */ fpm_globals.log_level = fpm_global_config.log_level; + if (fpm_global_config.process_max < 0) { + zlog(ZLOG_ERROR, "process_max can't be negative"); + return -1; + } + if (!fpm_global_config.error_log) { fpm_global_config.error_log = strdup("log/php-fpm.log"); } @@ -1394,6 +1401,7 @@ static void fpm_conf_dump() /* {{{ */ zlog(ZLOG_NOTICE, "\tsyslog.facility = %d", fpm_global_config.syslog_facility); /* FIXME: convert to string */ #endif zlog(ZLOG_NOTICE, "\tprocess_control_timeout = %ds", fpm_global_config.process_control_timeout); + zlog(ZLOG_NOTICE, "\tprocess.max = %d", fpm_global_config.process_max); zlog(ZLOG_NOTICE, "\temergency_restart_interval = %ds", fpm_global_config.emergency_restart_interval); zlog(ZLOG_NOTICE, "\temergency_restart_threshold = %d", fpm_global_config.emergency_restart_threshold); zlog(ZLOG_NOTICE, "\trlimit_files = %d", fpm_global_config.rlimit_files); diff --git a/sapi/fpm/fpm/fpm_conf.h b/sapi/fpm/fpm/fpm_conf.h index d19c2b61f5..11c688ae7b 100644 --- a/sapi/fpm/fpm/fpm_conf.h +++ b/sapi/fpm/fpm/fpm_conf.h @@ -32,6 +32,7 @@ struct fpm_global_config_s { #endif int rlimit_files; int rlimit_core; + int process_max; }; extern struct fpm_global_config_s fpm_global_config; diff --git a/sapi/fpm/php-fpm.conf.in b/sapi/fpm/php-fpm.conf.in index a4cdf66026..d35ed27787 100644 --- a/sapi/fpm/php-fpm.conf.in +++ b/sapi/fpm/php-fpm.conf.in @@ -69,6 +69,13 @@ ; Default Value: 0 ;process_control_timeout = 0 +; The maximum number of processes FPM will fork. This has been design to control +; the global number of processes when using dynamic PM within a lot of pools. +; Use it with caution. +; Note: A value of 0 indicates no limit +; Default Value: 0 +; process.max = 128 + ; Send FPM to background. Set to 'no' to keep FPM in foreground for debugging. ; Default Value: yes ;daemonize = yes |