Skip to content

Commit ba65b37

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

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

sapi/fpm/fpm/fpm_conf.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ static struct ini_value_parser_s ini_fpm_pool_options[] = {
146146
{ "access.format", &fpm_conf_set_string, WPO(access_format) },
147147
{ "slowlog", &fpm_conf_set_string, WPO(slowlog) },
148148
{ "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) },
149150
{ "request_terminate_timeout", &fpm_conf_set_time, WPO(request_terminate_timeout) },
150151
{ "rlimit_files", &fpm_conf_set_integer, WPO(rlimit_files) },
151152
{ "rlimit_core", &fpm_conf_set_rlimit_core, WPO(rlimit_core) },
@@ -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

@@ -1635,6 +1660,7 @@ static void fpm_conf_dump() /* {{{ */
16351660
zlog(ZLOG_NOTICE, "\taccess.format = %s", STR2STR(wp->config->access_format));
16361661
zlog(ZLOG_NOTICE, "\tslowlog = %s", STR2STR(wp->config->slowlog));
16371662
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);
16381664
zlog(ZLOG_NOTICE, "\trequest_terminate_timeout = %ds", wp->config->request_terminate_timeout);
16391665
zlog(ZLOG_NOTICE, "\trlimit_files = %d", wp->config->rlimit_files);
16401666
zlog(ZLOG_NOTICE, "\trlimit_core = %d", wp->config->rlimit_core);

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)