Skip to content

Commit 115020f

Browse files
author
fat
committed
Added master rlimit_files and rlimit_core in the global configuration settings
git-svn-id: http://svn.php.net/repository/php/php-src/trunk@312261 c90b9560-bf6c-de11-be94-00142212c4b1
1 parent 23250d5 commit 115020f

File tree

4 files changed

+48
-11
lines changed

4 files changed

+48
-11
lines changed

sapi/fpm/fpm/fpm_conf.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,15 @@ static char *ini_include = NULL;
6363
#define WPO(field) offsetof(struct fpm_worker_pool_config_s, field)
6464

6565
static struct ini_value_parser_s ini_fpm_global_options[] = {
66-
{ "emergency_restart_threshold", &fpm_conf_set_integer, GO(emergency_restart_threshold) },
67-
{ "emergency_restart_interval", &fpm_conf_set_time, GO(emergency_restart_interval) },
68-
{ "process_control_timeout", &fpm_conf_set_time, GO(process_control_timeout) },
69-
{ "daemonize", &fpm_conf_set_boolean, GO(daemonize) },
70-
{ "pid", &fpm_conf_set_string, GO(pid_file) },
71-
{ "error_log", &fpm_conf_set_string, GO(error_log) },
66+
{ "emergency_restart_threshold", &fpm_conf_set_integer, GO(emergency_restart_threshold) },
67+
{ "emergency_restart_interval", &fpm_conf_set_time, GO(emergency_restart_interval) },
68+
{ "process_control_timeout", &fpm_conf_set_time, GO(process_control_timeout) },
69+
{ "daemonize", &fpm_conf_set_boolean, GO(daemonize) },
70+
{ "pid", &fpm_conf_set_string, GO(pid_file) },
71+
{ "error_log", &fpm_conf_set_string, GO(error_log) },
7272
{ "log_level", &fpm_conf_set_log_level, 0 },
73+
{ "rlimit_files", &fpm_conf_set_integer, GO(rlimit_files) },
74+
{ "rlimit_core", &fpm_conf_set_rlimit_core,GO(rlimit_core) },
7375
{ 0, 0, 0 }
7476
};
7577

@@ -255,10 +257,10 @@ static char *fpm_conf_set_log_level(zval *value, void **config, intptr_t offset)
255257
static char *fpm_conf_set_rlimit_core(zval *value, void **config, intptr_t offset) /* {{{ */
256258
{
257259
char *val = Z_STRVAL_P(value);
258-
struct fpm_worker_pool_config_s *c = *config;
260+
int *ptr = (int *) ((char *) *config + offset);
259261

260262
if (!strcasecmp(val, "unlimited")) {
261-
c->rlimit_core = -1;
263+
*ptr = -1;
262264
} else {
263265
int int_value;
264266
void *subconf = &int_value;
@@ -274,7 +276,7 @@ static char *fpm_conf_set_rlimit_core(zval *value, void **config, intptr_t offse
274276
return "must be greater than zero or 'unlimited'";
275277
}
276278

277-
c->rlimit_core = int_value;
279+
*ptr = int_value;
278280
}
279281

280282
return NULL;
@@ -1117,6 +1119,8 @@ static void fpm_conf_dump() /* {{{ */
11171119
zlog(ZLOG_NOTICE, "\tprocess_control_timeout = %ds", fpm_global_config.process_control_timeout);
11181120
zlog(ZLOG_NOTICE, "\temergency_restart_interval = %ds", fpm_global_config.emergency_restart_interval);
11191121
zlog(ZLOG_NOTICE, "\temergency_restart_threshold = %d", fpm_global_config.emergency_restart_threshold);
1122+
zlog(ZLOG_NOTICE, "\trlimit_files = %d", fpm_global_config.rlimit_files);
1123+
zlog(ZLOG_NOTICE, "\trlimit_core = %d", fpm_global_config.rlimit_core);
11201124
zlog(ZLOG_NOTICE, " ");
11211125

11221126
for (wp = fpm_worker_all_pools; wp; wp = wp->next) {

sapi/fpm/fpm/fpm_conf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ struct fpm_global_config_s {
2929
int daemonize;
3030
char *pid_file;
3131
char *error_log;
32+
int rlimit_files;
33+
int rlimit_core;
3234
};
3335

3436
extern struct fpm_global_config_s fpm_global_config;

sapi/fpm/fpm/fpm_unix.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ int fpm_unix_init_child(struct fpm_worker_pool_s *wp) /* {{{ */
153153
r.rlim_max = r.rlim_cur = (rlim_t) wp->config->rlimit_files;
154154

155155
if (0 > setrlimit(RLIMIT_NOFILE, &r)) {
156-
zlog(ZLOG_SYSERROR, "[pool %s] setrlimit(RLIMIT_NOFILE, %d) failed (%d)", wp->config->name, wp->config->rlimit_files, errno);
156+
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);
157157
}
158158
}
159159

@@ -163,7 +163,7 @@ int fpm_unix_init_child(struct fpm_worker_pool_s *wp) /* {{{ */
163163
r.rlim_max = r.rlim_cur = wp->config->rlimit_core == -1 ? (rlim_t) RLIM_INFINITY : (rlim_t) wp->config->rlimit_core;
164164

165165
if (0 > setrlimit(RLIMIT_CORE, &r)) {
166-
zlog(ZLOG_SYSERROR, "[pool %s] setrlimit(RLIMIT_CORE, %d) failed (%d)", wp->config->name, wp->config->rlimit_core, errno);
166+
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);
167167
}
168168
}
169169

@@ -220,6 +220,28 @@ int fpm_unix_init_main() /* {{{ */
220220
{
221221
struct fpm_worker_pool_s *wp;
222222

223+
if (fpm_global_config.rlimit_files) {
224+
struct rlimit r;
225+
226+
r.rlim_max = r.rlim_cur = (rlim_t) fpm_global_config.rlimit_files;
227+
228+
if (0 > setrlimit(RLIMIT_NOFILE, &r)) {
229+
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);
230+
return -1;
231+
}
232+
}
233+
234+
if (fpm_global_config.rlimit_core) {
235+
struct rlimit r;
236+
237+
r.rlim_max = r.rlim_cur = fpm_global_config.rlimit_core == -1 ? (rlim_t) RLIM_INFINITY : (rlim_t) fpm_global_config.rlimit_core;
238+
239+
if (0 > setrlimit(RLIMIT_CORE, &r)) {
240+
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);
241+
return -1;
242+
}
243+
}
244+
223245
fpm_pagesize = getpagesize();
224246
if (fpm_global_config.daemonize) {
225247
switch (fork()) {

sapi/fpm/php-fpm.conf.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@
5757
; Send FPM to background. Set to 'no' to keep FPM in foreground for debugging.
5858
; Default Value: yes
5959
;daemonize = yes
60+
61+
; Set open file descriptor rlimit for the master process.
62+
; Default Value: system defined value
63+
;rlimit_files = 1024
64+
65+
; Set max core size rlimit for the master process.
66+
; Possible Values: 'unlimited' or an integer greater or equal to 0
67+
; Default Value: system defined value
68+
;rlimit_core = 0
6069

6170
;;;;;;;;;;;;;;;;;;;;
6271
; Pool Definitions ;

0 commit comments

Comments
 (0)