From 140def4ac712acac6e2561f65e1b72f8efad8717 Mon Sep 17 00:00:00 2001 From: Till Backhaus Date: Sun, 25 Feb 2018 12:08:47 +0100 Subject: Implement fpm_get_status --- sapi/fpm/fpm/fpm_main.c | 12 +++++ sapi/fpm/fpm/fpm_status.c | 99 +++++++++++++++++++++++++++++++++- sapi/fpm/fpm/fpm_status.h | 1 + sapi/fpm/tests/025.phpt | 132 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 243 insertions(+), 1 deletion(-) create mode 100644 sapi/fpm/tests/025.phpt diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c index e815be4700..673ae447b4 100644 --- a/sapi/fpm/fpm/fpm_main.c +++ b/sapi/fpm/fpm/fpm_main.c @@ -1566,8 +1566,20 @@ PHP_FUNCTION(apache_request_headers) /* {{{ */ } } /* }}} */ +/* {{{ proto array fpm_get_status + * Returns the status of the fastcgi process manager */ +PHP_FUNCTION(fpm_get_status) /* {{{ */ +{ + int error = fpm_status_export_to_zval(return_value); + if(error){ + RETURN_FALSE; + } +} +/* }}} */ + static const zend_function_entry cgi_fcgi_sapi_functions[] = { PHP_FE(fastcgi_finish_request, cgi_fcgi_sapi_no_arginfo) + PHP_FE(fpm_get_status, NULL) PHP_FE(apache_request_headers, cgi_fcgi_sapi_no_arginfo) PHP_FALIAS(getallheaders, apache_request_headers, cgi_fcgi_sapi_no_arginfo) PHP_FE_END diff --git a/sapi/fpm/fpm/fpm_status.c b/sapi/fpm/fpm/fpm_status.c index a8cfb3fa49..2df0714409 100644 --- a/sapi/fpm/fpm/fpm_status.c +++ b/sapi/fpm/fpm/fpm_status.c @@ -3,6 +3,7 @@ /* (c) 2009 Jerome Loyet */ #include "php.h" +#include "zend_long.h" #include "SAPI.h" #include @@ -45,6 +46,103 @@ int fpm_status_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ } /* }}} */ +int fpm_status_export_to_zval(zval *status) +{ + struct fpm_scoreboard_s scoreboard, *scoreboard_p; + zval fpm_proc_stats, fpm_proc_stat; + time_t now_epoch; + struct timeval duration, now; + double cpu; + int i; + + + scoreboard_p = fpm_scoreboard_acquire(NULL, 1); + if (!scoreboard_p) { + zlog(ZLOG_NOTICE, "[pool %s] status: scoreboard already in use.", scoreboard_p->pool); + return -1; + } + + /* copy the scoreboard not to bother other processes */ + scoreboard = *scoreboard_p; + struct fpm_scoreboard_proc_s procs[scoreboard.nprocs]; + + struct fpm_scoreboard_proc_s *proc_p; + for(i=0; i +--FILE-- + +Done +--EXPECTF-- +[%s] NOTICE: fpm is running, pid %d +[%s] NOTICE: ready to handle connections +Test Start +array(15) { + ["pool"]=> + string(10) "unconfined" + ["process-manager"]=> + string(7) "dynamic" + ["start-time"]=> + int(%d) + ["start-since"]=> + int(%d) + ["accepted-conn"]=> + int(1) + ["listen-queue"]=> + int(0) + ["max-listen-queue"]=> + int(0) + ["listen-queue-len"]=> + int(128) + ["idle-processes"]=> + int(0) + ["active-processes"]=> + int(1) + ["total-processes"]=> + int(1) + ["max-active-processes"]=> + int(1) + ["max-children-reached"]=> + int(0) + ["slow-requests"]=> + int(0) + ["procs"]=> + array(1) { + [0]=> + array(14) { + ["pid"]=> + int(%d) + ["state"]=> + string(7) "Running" + ["start-time"]=> + int(%d) + ["start-since"]=> + int(%d) + ["requests"]=> + int(1) + ["request-duration"]=> + int(%d) + ["request-method"]=> + string(3) "GET" + ["request-uri"]=> + string(%d) "%s" + ["query-string"]=> + string(0) "" + ["request-length"]=> + int(0) + ["user"]=> + string(1) "-" + ["script"]=> + string(%d) "%s" + ["last-request-cpu"]=> + float(0) + ["last-request-memory"]=> + int(0) + } + } +} +Test End + +Request ok +[%s] NOTICE: Terminating ... +[%s] NOTICE: exiting, bye-bye! +Done +--CLEAN-- + -- cgit v1.2.1