.syslog_facility = -1,
#endif
.process_max = 0,
+ .process_priority = 64, /* 64 means unset */
};
static struct fpm_worker_pool_s *current_wp = NULL;
static int ini_recursion = 0;
{ "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) },
+ { "process.priority", &fpm_conf_set_integer, GO(process_priority) },
{ "daemonize", &fpm_conf_set_boolean, GO(daemonize) },
{ "rlimit_files", &fpm_conf_set_integer, GO(rlimit_files) },
{ "rlimit_core", &fpm_conf_set_rlimit_core, GO(rlimit_core) },
{ "listen.group", &fpm_conf_set_string, WPO(listen_group) },
{ "listen.mode", &fpm_conf_set_string, WPO(listen_mode) },
{ "listen.allowed_clients", &fpm_conf_set_string, WPO(listen_allowed_clients) },
+ { "process.priority", &fpm_conf_set_integer, WPO(process_priority) },
{ "pm", &fpm_conf_set_pm, WPO(pm) },
{ "pm.max_children", &fpm_conf_set_integer, WPO(pm_max_children) },
{ "pm.start_servers", &fpm_conf_set_integer, WPO(pm_start_servers) },
memset(wp->config, 0, sizeof(struct fpm_worker_pool_config_s));
wp->config->listen_backlog = FPM_BACKLOG_DEFAULT;
wp->config->pm_process_idle_timeout = 10; /* 10s by default */
+ wp->config->process_priority = 64; /* 64 means unset */
if (!fpm_worker_all_pools) {
fpm_worker_all_pools = wp;
return -1;
}
+ if (wp->config->process_priority != 64 && (wp->config->process_priority < -19 || wp->config->process_priority > 20)) {
+ zlog(ZLOG_ERROR, "[pool %s] process.priority must be included into [-19,20]", wp->config->name);
+ return -1;
+ }
+
/* pm */
if (wp->config->pm != PM_STYLE_STATIC && wp->config->pm != PM_STYLE_DYNAMIC && wp->config->pm != PM_STYLE_ONDEMAND) {
zlog(ZLOG_ALERT, "[pool %s] the process manager is missing (static, dynamic or ondemand)", wp->config->name);
return -1;
}
+ if (fpm_global_config.process_priority != 64 && (fpm_global_config.process_priority < -19 || fpm_global_config.process_priority > 20)) {
+ zlog(ZLOG_ERROR, "process.priority must be included into [-19,20]");
+ return -1;
+ }
+
if (!fpm_global_config.error_log) {
fpm_global_config.error_log = strdup("log/php-fpm.log");
}
zlog(ZLOG_NOTICE, "\temergency_restart_threshold = %d", fpm_global_config.emergency_restart_threshold);
zlog(ZLOG_NOTICE, "\tprocess_control_timeout = %ds", fpm_global_config.process_control_timeout);
zlog(ZLOG_NOTICE, "\tprocess.max = %d", fpm_global_config.process_max);
+ if (fpm_global_config.process_priority == 64) {
+ zlog(ZLOG_NOTICE, "\tprocess.priority = undefined");
+ } else {
+ zlog(ZLOG_NOTICE, "\tprocess.priority = %d", fpm_global_config.process_priority);
+ }
zlog(ZLOG_NOTICE, "\tdaemonize = %s", BOOL2STR(fpm_global_config.daemonize));
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, "\tlisten.group = %s", STR2STR(wp->config->listen_group));
zlog(ZLOG_NOTICE, "\tlisten.mode = %s", STR2STR(wp->config->listen_mode));
zlog(ZLOG_NOTICE, "\tlisten.allowed_clients = %s", STR2STR(wp->config->listen_allowed_clients));
+ if (wp->config->process_priority == 64) {
+ zlog(ZLOG_NOTICE, "\tprocess.priority = undefined");
+ } else {
+ zlog(ZLOG_NOTICE, "\tprocess.priority = %d", wp->config->process_priority);
+ }
zlog(ZLOG_NOTICE, "\tpm = %s", PM2STR(wp->config->pm));
zlog(ZLOG_NOTICE, "\tpm.max_children = %d", wp->config->pm_max_children);
zlog(ZLOG_NOTICE, "\tpm.start_servers = %d", wp->config->pm_start_servers);
if (wp->config->chroot && *wp->config->chroot) {
zlog(ZLOG_WARNING, "[pool %s] 'chroot' directive is ignored when FPM is not running as root", wp->config->name);
}
+ if (wp->config->process_priority != 64) {
+ zlog(ZLOG_WARNING, "[pool %s] 'process.priority' directive is ignored when FPM is not running as root", wp->config->name);
+ }
/* set up HOME and USER anyway */
pwd = getpwuid(getuid());
}
if (is_root) {
+
+ if (wp->config->process_priority != 64) {
+ if (setpriority(PRIO_PROCESS, 0, wp->config->process_priority) < 0) {
+ zlog(ZLOG_SYSERROR, "[pool %s] Unable to set priority for this new process", wp->config->name);
+ return -1;
+ }
+ }
+
if (wp->set_gid) {
if (0 > setgid(wp->set_gid)) {
zlog(ZLOG_SYSERROR, "[pool %s] failed to setgid(%d)", wp->config->name, wp->set_gid);
int fpm_unix_init_main() /* {{{ */
{
struct fpm_worker_pool_s *wp;
+ int is_root = !geteuid();
if (fpm_global_config.rlimit_files) {
struct rlimit r;
return -1;
}
+ if (fpm_global_config.process_priority != 64) {
+ if (is_root) {
+ if (setpriority(PRIO_PROCESS, 0, fpm_global_config.process_priority) < 0) {
+ zlog(ZLOG_SYSERROR, "Unable to set priority for the master process");
+ return -1;
+ }
+ } else {
+ zlog(ZLOG_WARNING, "'process.priority' directive is ignored when FPM is not running as root");
+ }
+ }
+
fpm_globals.parent_pid = getpid();
for (wp = fpm_worker_all_pools; wp; wp = wp->next) {
if (0 > fpm_unix_conf_wp(wp)) {