]> granicus.if.org Git - php/commitdiff
Added master rlimit_files and rlimit_core in the global configuration settings
authorJérôme Loyet <fat@php.net>
Sat, 18 Jun 2011 16:27:48 +0000 (16:27 +0000)
committerJérôme Loyet <fat@php.net>
Sat, 18 Jun 2011 16:27:48 +0000 (16:27 +0000)
NEWS
sapi/fpm/fpm/fpm_conf.c
sapi/fpm/fpm/fpm_conf.h
sapi/fpm/fpm/fpm_unix.c
sapi/fpm/php-fpm.conf.in

diff --git a/NEWS b/NEWS
index 78f7bd7bd0385d78d1df6b4c4a4464b38dbeb697..e43ad83b8c5e3afb0902ada0aba0e7679dedc240 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -175,6 +175,8 @@ PHP                                                                        NEWS
   . Added xml format to the status page. (fat)
   . Remove timestamp in logs written by children processes. (fat)
   . Fixed exit at FPM startup on fpm_resources_prepare() errors. (fat)
+  . Added master rlimit_files and rlimit_core in the global configuration
+    settings. (fat)
 
 - Reflection extension:
   . Fixed bug #54347 (reflection_extension does not lowercase module function
index 5d6fe770cd92e2bf49b2e5504490f7d598150305..a8e2d60e26ec038339ac9c0c415e6c6e84acf2bc 100644 (file)
@@ -63,13 +63,15 @@ static char *ini_include = NULL;
 #define WPO(field) offsetof(struct fpm_worker_pool_config_s, field)
 
 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) },
-       { "daemonize",                                                                          &fpm_conf_set_boolean,  GO(daemonize) },
-       { "pid",                                                                                                        &fpm_conf_set_string,           GO(pid_file) },
-       { "error_log",                                                                          &fpm_conf_set_string,           GO(error_log) },
+       { "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) },
+       { "daemonize",                                                                          &fpm_conf_set_boolean,          GO(daemonize) },
+       { "pid",                                                                                                        &fpm_conf_set_string,                   GO(pid_file) },
+       { "error_log",                                                                          &fpm_conf_set_string,                   GO(error_log) },
        { "log_level",                                                                          &fpm_conf_set_log_level,        0 },
+       { "rlimit_files",                                                                       &fpm_conf_set_integer,          GO(rlimit_files) },
+       { "rlimit_core",                                                                        &fpm_conf_set_rlimit_core,GO(rlimit_core) },
        { 0, 0, 0 }
 };
 
@@ -255,10 +257,10 @@ static char *fpm_conf_set_log_level(zval *value, void **config, intptr_t offset)
 static char *fpm_conf_set_rlimit_core(zval *value, void **config, intptr_t offset) /* {{{ */
 {
        char *val = Z_STRVAL_P(value);
-       struct fpm_worker_pool_config_s *c = *config;
+       int *ptr = (int *) ((char *) *config + offset);
 
        if (!strcasecmp(val, "unlimited")) {
-               c->rlimit_core = -1;
+               *ptr = -1;
        } else {
                int int_value;
                void *subconf = &int_value;
@@ -274,7 +276,7 @@ static char *fpm_conf_set_rlimit_core(zval *value, void **config, intptr_t offse
                        return "must be greater than zero or 'unlimited'";
                }
 
-               c->rlimit_core = int_value;
+               *ptr = int_value;
        }
 
        return NULL;
@@ -1117,6 +1119,8 @@ static void fpm_conf_dump() /* {{{ */
        zlog(ZLOG_NOTICE, "\tprocess_control_timeout = %ds", fpm_global_config.process_control_timeout);
        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);
+       zlog(ZLOG_NOTICE, "\trlimit_core = %d", fpm_global_config.rlimit_core);
        zlog(ZLOG_NOTICE, " ");
 
        for (wp = fpm_worker_all_pools; wp; wp = wp->next) {
index ac38ee2e9a0c467b9eae4b58df6524687fc31ded..64b569006efb438a69e85f577957abd9b8624175 100644 (file)
@@ -29,6 +29,8 @@ struct fpm_global_config_s {
        int daemonize;
        char *pid_file;
        char *error_log;
+       int rlimit_files;
+       int rlimit_core;
 };
 
 extern struct fpm_global_config_s fpm_global_config;
index d63ea4d5b01fc4b54fd7187f8c533ca2d538fbca..d29d3879950f01855b5145e7e44f830066a50b20 100644 (file)
@@ -153,7 +153,7 @@ int fpm_unix_init_child(struct fpm_worker_pool_s *wp) /* {{{ */
                r.rlim_max = r.rlim_cur = (rlim_t) wp->config->rlimit_files;
 
                if (0 > setrlimit(RLIMIT_NOFILE, &r)) {
-                       zlog(ZLOG_SYSERROR, "[pool %s] setrlimit(RLIMIT_NOFILE, %d) failed (%d)", wp->config->name, wp->config->rlimit_files, errno);
+                       zlog(ZLOG_SYSERROR, "[pool %s] unable to set rlimit_files for this pool. Please check your system limits or decrease rlimit_files. setrlimit(RLIMIT_NOFILE, %d) failed (%d)", wp->config->name, wp->config->rlimit_files, errno);
                }
        }
 
@@ -163,7 +163,7 @@ int fpm_unix_init_child(struct fpm_worker_pool_s *wp) /* {{{ */
                r.rlim_max = r.rlim_cur = wp->config->rlimit_core == -1 ? (rlim_t) RLIM_INFINITY : (rlim_t) wp->config->rlimit_core;
 
                if (0 > setrlimit(RLIMIT_CORE, &r)) {
-                       zlog(ZLOG_SYSERROR, "[pool %s] setrlimit(RLIMIT_CORE, %d) failed (%d)", wp->config->name, wp->config->rlimit_core, errno);
+                       zlog(ZLOG_SYSERROR, "[pool %s] unable to set rlimit_core for this pool. Please check your system limits or decrease rlimit_core. setrlimit(RLIMIT_CORE, %d) failed (%d)", wp->config->name, wp->config->rlimit_core, errno);
                }
        }
 
@@ -220,6 +220,28 @@ int fpm_unix_init_main() /* {{{ */
 {
        struct fpm_worker_pool_s *wp;
 
+       if (fpm_global_config.rlimit_files) {
+               struct rlimit r;
+
+               r.rlim_max = r.rlim_cur = (rlim_t) fpm_global_config.rlimit_files;
+
+               if (0 > setrlimit(RLIMIT_NOFILE, &r)) {
+                       zlog(ZLOG_SYSERROR, "unable to set rlimit_core for this pool. Please check your system limits or decrease rlimit_files. setrlimit(RLIMIT_NOFILE, %d) failed (%d)", fpm_global_config.rlimit_files, errno);
+                       return -1;
+               }
+       }
+
+       if (fpm_global_config.rlimit_core) {
+               struct rlimit r;
+
+               r.rlim_max = r.rlim_cur = fpm_global_config.rlimit_core == -1 ? (rlim_t) RLIM_INFINITY : (rlim_t) fpm_global_config.rlimit_core;
+
+               if (0 > setrlimit(RLIMIT_CORE, &r)) {
+                       zlog(ZLOG_SYSERROR, "unable to set rlimit_core for this pool. Please check your system limits or decrease rlimit_core. setrlimit(RLIMIT_CORE, %d) failed (%d)", fpm_global_config.rlimit_core, errno);
+                       return -1;
+               }
+       }
+
        fpm_pagesize = getpagesize();
        if (fpm_global_config.daemonize) {
                switch (fork()) {
index 6821789bd12bf848d4fe8b9a626ed0fb2254289a..e8b39bcdeafec32e6c50007ab81a0e066a41f5a5 100644 (file)
 ; Send FPM to background. Set to 'no' to keep FPM in foreground for debugging.
 ; Default Value: yes
 ;daemonize = yes
+; Set open file descriptor rlimit for the master process.
+; Default Value: system defined value
+;rlimit_files = 1024
+; Set max core size rlimit for the master process.
+; Possible Values: 'unlimited' or an integer greater or equal to 0
+; Default Value: system defined value
+;rlimit_core = 0
 
 ;;;;;;;;;;;;;;;;;;;;
 ; Pool Definitions ;