Skip to content

Commit 68ca39e

Browse files
committed
Allow to configure php-fpm slow log trace callers limit
1 parent 5ac4973 commit 68ca39e

File tree

4 files changed

+89
-58
lines changed

4 files changed

+89
-58
lines changed

sapi/fpm/fpm/fpm_conf.c

Lines changed: 83 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -118,44 +118,45 @@ static struct ini_value_parser_s ini_fpm_global_options[] = {
118118
* Please keep the same order as in fpm_conf.h and in php-fpm.conf.in
119119
*/
120120
static struct ini_value_parser_s ini_fpm_pool_options[] = {
121-
{ "prefix", &fpm_conf_set_string, WPO(prefix) },
122-
{ "user", &fpm_conf_set_string, WPO(user) },
123-
{ "group", &fpm_conf_set_string, WPO(group) },
124-
{ "listen", &fpm_conf_set_string, WPO(listen_address) },
125-
{ "listen.backlog", &fpm_conf_set_integer, WPO(listen_backlog) },
121+
{ "prefix", &fpm_conf_set_string, WPO(prefix) },
122+
{ "user", &fpm_conf_set_string, WPO(user) },
123+
{ "group", &fpm_conf_set_string, WPO(group) },
124+
{ "listen", &fpm_conf_set_string, WPO(listen_address) },
125+
{ "listen.backlog", &fpm_conf_set_integer, WPO(listen_backlog) },
126126
#ifdef HAVE_FPM_ACL
127-
{ "listen.acl_users", &fpm_conf_set_string, WPO(listen_acl_users) },
128-
{ "listen.acl_groups", &fpm_conf_set_string, WPO(listen_acl_groups) },
127+
{ "listen.acl_users", &fpm_conf_set_string, WPO(listen_acl_users) },
128+
{ "listen.acl_groups", &fpm_conf_set_string, WPO(listen_acl_groups) },
129129
#endif
130-
{ "listen.owner", &fpm_conf_set_string, WPO(listen_owner) },
131-
{ "listen.group", &fpm_conf_set_string, WPO(listen_group) },
132-
{ "listen.mode", &fpm_conf_set_string, WPO(listen_mode) },
133-
{ "listen.allowed_clients", &fpm_conf_set_string, WPO(listen_allowed_clients) },
134-
{ "process.priority", &fpm_conf_set_integer, WPO(process_priority) },
135-
{ "pm", &fpm_conf_set_pm, WPO(pm) },
136-
{ "pm.max_children", &fpm_conf_set_integer, WPO(pm_max_children) },
137-
{ "pm.start_servers", &fpm_conf_set_integer, WPO(pm_start_servers) },
138-
{ "pm.min_spare_servers", &fpm_conf_set_integer, WPO(pm_min_spare_servers) },
139-
{ "pm.max_spare_servers", &fpm_conf_set_integer, WPO(pm_max_spare_servers) },
140-
{ "pm.process_idle_timeout", &fpm_conf_set_time, WPO(pm_process_idle_timeout) },
141-
{ "pm.max_requests", &fpm_conf_set_integer, WPO(pm_max_requests) },
142-
{ "pm.status_path", &fpm_conf_set_string, WPO(pm_status_path) },
143-
{ "ping.path", &fpm_conf_set_string, WPO(ping_path) },
144-
{ "ping.response", &fpm_conf_set_string, WPO(ping_response) },
145-
{ "access.log", &fpm_conf_set_string, WPO(access_log) },
146-
{ "access.format", &fpm_conf_set_string, WPO(access_format) },
147-
{ "slowlog", &fpm_conf_set_string, WPO(slowlog) },
148-
{ "request_slowlog_timeout", &fpm_conf_set_time, WPO(request_slowlog_timeout) },
149-
{ "request_terminate_timeout", &fpm_conf_set_time, WPO(request_terminate_timeout) },
150-
{ "rlimit_files", &fpm_conf_set_integer, WPO(rlimit_files) },
151-
{ "rlimit_core", &fpm_conf_set_rlimit_core, WPO(rlimit_core) },
152-
{ "chroot", &fpm_conf_set_string, WPO(chroot) },
153-
{ "chdir", &fpm_conf_set_string, WPO(chdir) },
154-
{ "catch_workers_output", &fpm_conf_set_boolean, WPO(catch_workers_output) },
155-
{ "clear_env", &fpm_conf_set_boolean, WPO(clear_env) },
156-
{ "security.limit_extensions", &fpm_conf_set_string, WPO(security_limit_extensions) },
130+
{ "listen.owner", &fpm_conf_set_string, WPO(listen_owner) },
131+
{ "listen.group", &fpm_conf_set_string, WPO(listen_group) },
132+
{ "listen.mode", &fpm_conf_set_string, WPO(listen_mode) },
133+
{ "listen.allowed_clients", &fpm_conf_set_string, WPO(listen_allowed_clients) },
134+
{ "process.priority", &fpm_conf_set_integer, WPO(process_priority) },
135+
{ "pm", &fpm_conf_set_pm, WPO(pm) },
136+
{ "pm.max_children", &fpm_conf_set_integer, WPO(pm_max_children) },
137+
{ "pm.start_servers", &fpm_conf_set_integer, WPO(pm_start_servers) },
138+
{ "pm.min_spare_servers", &fpm_conf_set_integer, WPO(pm_min_spare_servers) },
139+
{ "pm.max_spare_servers", &fpm_conf_set_integer, WPO(pm_max_spare_servers) },
140+
{ "pm.process_idle_timeout", &fpm_conf_set_time, WPO(pm_process_idle_timeout) },
141+
{ "pm.max_requests", &fpm_conf_set_integer, WPO(pm_max_requests) },
142+
{ "pm.status_path", &fpm_conf_set_string, WPO(pm_status_path) },
143+
{ "ping.path", &fpm_conf_set_string, WPO(ping_path) },
144+
{ "ping.response", &fpm_conf_set_string, WPO(ping_response) },
145+
{ "access.log", &fpm_conf_set_string, WPO(access_log) },
146+
{ "access.format", &fpm_conf_set_string, WPO(access_format) },
147+
{ "slowlog", &fpm_conf_set_string, WPO(slowlog) },
148+
{ "request_slowlog_timeout", &fpm_conf_set_time, WPO(request_slowlog_timeout) },
149+
{ "request_slowlog_trace_depth", &fpm_conf_set_integer, WPO(request_slowlog_trace_depth) },
150+
{ "request_terminate_timeout", &fpm_conf_set_time, WPO(request_terminate_timeout) },
151+
{ "rlimit_files", &fpm_conf_set_integer, WPO(rlimit_files) },
152+
{ "rlimit_core", &fpm_conf_set_rlimit_core, WPO(rlimit_core) },
153+
{ "chroot", &fpm_conf_set_string, WPO(chroot) },
154+
{ "chdir", &fpm_conf_set_string, WPO(chdir) },
155+
{ "catch_workers_output", &fpm_conf_set_boolean, WPO(catch_workers_output) },
156+
{ "clear_env", &fpm_conf_set_boolean, WPO(clear_env) },
157+
{ "security.limit_extensions", &fpm_conf_set_string, WPO(security_limit_extensions) },
157158
#ifdef HAVE_APPARMOR
158-
{ "apparmor_hat", &fpm_conf_set_string, WPO(apparmor_hat) },
159+
{ "apparmor_hat", &fpm_conf_set_string, WPO(apparmor_hat) },
159160
#endif
160161
{ 0, 0, 0 }
161162
};
@@ -970,6 +971,30 @@ static int fpm_conf_process_all_pools() /* {{{ */
970971
}
971972
}
972973

974+
/* request_slowlog_trace_depth */
975+
if (wp->config->request_slowlog_trace_depth) {
976+
#if HAVE_FPM_TRACE
977+
if (! (wp->config->slowlog && *wp->config->slowlog)) {
978+
zlog(ZLOG_ERROR, "[pool %s] 'slowlog' must be specified for use with 'request_slowlog_trace_depth'", wp->config->name);
979+
return -1;
980+
}
981+
#else
982+
static int warned = 0;
983+
984+
if (!warned) {
985+
zlog(ZLOG_WARNING, "[pool %s] 'request_slowlog_trace_depth' is not supported on your system", wp->config->name);
986+
warned = 1;
987+
}
988+
#endif
989+
990+
if (wp->config->request_slowlog_trace_depth <= 0) {
991+
zlog(ZLOG_ERROR, "[pool %s] 'request_slowlog_trace_depth' (%d) must be a positive value", wp->config->name, wp->config->request_slowlog_trace_depth);
992+
return -1;
993+
}
994+
} else {
995+
wp->config->request_slowlog_trace_depth = 20;
996+
}
997+
973998
/* chroot */
974999
if (wp->config->chroot && *wp->config->chroot) {
9751000

@@ -1621,28 +1646,29 @@ static void fpm_conf_dump() /* {{{ */
16211646
} else {
16221647
zlog(ZLOG_NOTICE, "\tprocess.priority = %d", wp->config->process_priority);
16231648
}
1624-
zlog(ZLOG_NOTICE, "\tpm = %s", PM2STR(wp->config->pm));
1625-
zlog(ZLOG_NOTICE, "\tpm.max_children = %d", wp->config->pm_max_children);
1626-
zlog(ZLOG_NOTICE, "\tpm.start_servers = %d", wp->config->pm_start_servers);
1627-
zlog(ZLOG_NOTICE, "\tpm.min_spare_servers = %d", wp->config->pm_min_spare_servers);
1628-
zlog(ZLOG_NOTICE, "\tpm.max_spare_servers = %d", wp->config->pm_max_spare_servers);
1629-
zlog(ZLOG_NOTICE, "\tpm.process_idle_timeout = %d", wp->config->pm_process_idle_timeout);
1630-
zlog(ZLOG_NOTICE, "\tpm.max_requests = %d", wp->config->pm_max_requests);
1631-
zlog(ZLOG_NOTICE, "\tpm.status_path = %s", STR2STR(wp->config->pm_status_path));
1632-
zlog(ZLOG_NOTICE, "\tping.path = %s", STR2STR(wp->config->ping_path));
1633-
zlog(ZLOG_NOTICE, "\tping.response = %s", STR2STR(wp->config->ping_response));
1634-
zlog(ZLOG_NOTICE, "\taccess.log = %s", STR2STR(wp->config->access_log));
1635-
zlog(ZLOG_NOTICE, "\taccess.format = %s", STR2STR(wp->config->access_format));
1636-
zlog(ZLOG_NOTICE, "\tslowlog = %s", STR2STR(wp->config->slowlog));
1637-
zlog(ZLOG_NOTICE, "\trequest_slowlog_timeout = %ds", wp->config->request_slowlog_timeout);
1638-
zlog(ZLOG_NOTICE, "\trequest_terminate_timeout = %ds", wp->config->request_terminate_timeout);
1639-
zlog(ZLOG_NOTICE, "\trlimit_files = %d", wp->config->rlimit_files);
1640-
zlog(ZLOG_NOTICE, "\trlimit_core = %d", wp->config->rlimit_core);
1641-
zlog(ZLOG_NOTICE, "\tchroot = %s", STR2STR(wp->config->chroot));
1642-
zlog(ZLOG_NOTICE, "\tchdir = %s", STR2STR(wp->config->chdir));
1643-
zlog(ZLOG_NOTICE, "\tcatch_workers_output = %s", BOOL2STR(wp->config->catch_workers_output));
1644-
zlog(ZLOG_NOTICE, "\tclear_env = %s", BOOL2STR(wp->config->clear_env));
1645-
zlog(ZLOG_NOTICE, "\tsecurity.limit_extensions = %s", wp->config->security_limit_extensions);
1649+
zlog(ZLOG_NOTICE, "\tpm = %s", PM2STR(wp->config->pm));
1650+
zlog(ZLOG_NOTICE, "\tpm.max_children = %d", wp->config->pm_max_children);
1651+
zlog(ZLOG_NOTICE, "\tpm.start_servers = %d", wp->config->pm_start_servers);
1652+
zlog(ZLOG_NOTICE, "\tpm.min_spare_servers = %d", wp->config->pm_min_spare_servers);
1653+
zlog(ZLOG_NOTICE, "\tpm.max_spare_servers = %d", wp->config->pm_max_spare_servers);
1654+
zlog(ZLOG_NOTICE, "\tpm.process_idle_timeout = %d", wp->config->pm_process_idle_timeout);
1655+
zlog(ZLOG_NOTICE, "\tpm.max_requests = %d", wp->config->pm_max_requests);
1656+
zlog(ZLOG_NOTICE, "\tpm.status_path = %s", STR2STR(wp->config->pm_status_path));
1657+
zlog(ZLOG_NOTICE, "\tping.path = %s", STR2STR(wp->config->ping_path));
1658+
zlog(ZLOG_NOTICE, "\tping.response = %s", STR2STR(wp->config->ping_response));
1659+
zlog(ZLOG_NOTICE, "\taccess.log = %s", STR2STR(wp->config->access_log));
1660+
zlog(ZLOG_NOTICE, "\taccess.format = %s", STR2STR(wp->config->access_format));
1661+
zlog(ZLOG_NOTICE, "\tslowlog = %s", STR2STR(wp->config->slowlog));
1662+
zlog(ZLOG_NOTICE, "\trequest_slowlog_timeout = %ds", wp->config->request_slowlog_timeout);
1663+
zlog(ZLOG_NOTICE, "\trequest_slowlog_trace_depth = %d", wp->config->request_slowlog_trace_depth);
1664+
zlog(ZLOG_NOTICE, "\trequest_terminate_timeout = %ds", wp->config->request_terminate_timeout);
1665+
zlog(ZLOG_NOTICE, "\trlimit_files = %d", wp->config->rlimit_files);
1666+
zlog(ZLOG_NOTICE, "\trlimit_core = %d", wp->config->rlimit_core);
1667+
zlog(ZLOG_NOTICE, "\tchroot = %s", STR2STR(wp->config->chroot));
1668+
zlog(ZLOG_NOTICE, "\tchdir = %s", STR2STR(wp->config->chdir));
1669+
zlog(ZLOG_NOTICE, "\tcatch_workers_output = %s", BOOL2STR(wp->config->catch_workers_output));
1670+
zlog(ZLOG_NOTICE, "\tclear_env = %s", BOOL2STR(wp->config->clear_env));
1671+
zlog(ZLOG_NOTICE, "\tsecurity.limit_extensions = %s", wp->config->security_limit_extensions);
16461672

16471673
for (kv = wp->config->env; kv; kv = kv->next) {
16481674
zlog(ZLOG_NOTICE, "\tenv[%s] = %s", kv->key, kv->value);

sapi/fpm/fpm/fpm_conf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ struct fpm_worker_pool_config_s {
7878
char *access_format;
7979
char *slowlog;
8080
int request_slowlog_timeout;
81+
int request_slowlog_trace_depth;
8182
int request_terminate_timeout;
8283
int rlimit_files;
8384
int rlimit_core;

sapi/fpm/fpm/fpm_php_trace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ */
4444
{
45-
int callers_limit = 20;
45+
int callers_limit = child->wp->config->request_slowlog_trace_depth;
4646
pid_t pid = child->pid;
4747
struct timeval tv;
4848
static const int buf_size = 1024;

sapi/fpm/www.conf.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,10 @@ pm.max_spare_servers = 3
322322
; Default Value: 0
323323
;request_slowlog_timeout = 0
324324

325+
; Depth of slow log stack trace.
326+
; Default Value: 20
327+
;request_slowlog_trace_depth = 20
328+
325329
; The timeout for serving a single request after which the worker process will
326330
; be killed. This option should be used when the 'max_execution_time' ini option
327331
; does not stop script execution for some reason. A value of '0' means 'off'.

0 commit comments

Comments
 (0)