summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJérôme Loyet <fat@php.net>2009-12-22 16:08:53 +0000
committerJérôme Loyet <fat@php.net>2009-12-22 16:08:53 +0000
commit22ce3898697cd5d5ede66b2639d92ed5eec5746e (patch)
tree2a34aa918851a3a66319ccbf972a2bdda90828c2
parent1e0a1721edf692c2d3d56f1daccc24353da87523 (diff)
downloadphp-git-22ce3898697cd5d5ede66b2639d92ed5eec5746e.tar.gz
Add html and json syntax to status page
-rw-r--r--sapi/fpm/fpm/fpm_main.c16
-rw-r--r--sapi/fpm/fpm/fpm_status.c82
-rw-r--r--sapi/fpm/fpm/fpm_status.h2
-rw-r--r--sapi/fpm/php-fpm.conf.in9
4 files changed, 93 insertions, 16 deletions
diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c
index 5d1e35d6e0..e2cc0d873f 100644
--- a/sapi/fpm/fpm/fpm_main.c
+++ b/sapi/fpm/fpm/fpm_main.c
@@ -1765,7 +1765,7 @@ consult the installation file that came with this distribution, or visit \n\
SG(server_context) = (void *) &request;
init_request_info(TSRMLS_C);
CG(interactive) = 0;
- char *status_buffer;
+ char *status_buffer, *status_content_type;
fpm_request_info();
@@ -1778,14 +1778,24 @@ consult the installation file that came with this distribution, or visit \n\
return FAILURE;
}
- if (!strcasecmp(SG(request_info).request_method, "GET") && fpm_status_handle_status(SG(request_info).request_uri, &status_buffer)) {
- sapi_add_header_ex(ZEND_STRL("Content-Type: text/plain"), 1, 1 TSRMLS_CC);
+ if (!strcasecmp(SG(request_info).request_method, "GET") && fpm_status_handle_status(SG(request_info).request_uri, SG(request_info).query_string, &status_buffer, &status_content_type)) {
if (status_buffer) {
int i;
+
+ if (status_content_type) {
+ sapi_add_header_ex(status_content_type, strlen(status_content_type), 1, 1 TSRMLS_CC);
+ } else {
+ sapi_add_header_ex(ZEND_STRL("Content-Type: text/plain"), 1, 1 TSRMLS_CC);
+ }
+
SG(sapi_headers).http_response_code = 200;
PUTS(status_buffer);
efree(status_buffer);
+ if (status_content_type) {
+ efree(status_content_type);
+ }
} else {
+ sapi_add_header_ex(ZEND_STRL("Content-Type: text/plain"), 1, 1 TSRMLS_CC);
SG(sapi_headers).http_response_code = 500;
PUTS("Unable to retrieve status\n");
}
diff --git a/sapi/fpm/fpm/fpm_status.c b/sapi/fpm/fpm/fpm_status.c
index ad897076a1..f05fafd432 100644
--- a/sapi/fpm/fpm/fpm_status.c
+++ b/sapi/fpm/fpm/fpm_status.c
@@ -144,12 +144,73 @@ int fpm_status_get(int *idle, int *active, int *total, int *pm) /* {{{ */
}
/* }}} */
+static void fpm_status_handle_status_txt(struct fpm_status_s *status, char **output, char **content_type) /* {{{ */
+{
+ if (!status || !output || !content_type) {
+ return;
+ }
+
+ spprintf(output, 0,
+ "accepted conn: %lu\n"
+ "pool: %s\n"
+ "process manager: %s\n"
+ "idle processes: %d\n"
+ "active processes: %d\n"
+ "total processes: %d\n",
+ status->accepted_conn, fpm_status_pool, status->pm == PM_STYLE_STATIC ? "static" : "dynamic", status->idle, status->active, status->total);
+
+ spprintf(content_type, 0, "text/plain");
+}
+/* }}} */
+
+static void fpm_status_handle_status_html(struct fpm_status_s *status, char **output, char **content_type) /* {{{ */
+{
+ if (!status || !output || !content_type) {
+ return;
+ }
+
+ spprintf(output, 0,
+ "<table>\n"
+ "<tr><th>accepted conn</th><td>%lu</td></tr>\n"
+ "<tr><th>pool</th><td>%s</td></tr>\n"
+ "<tr><th>process manager</th><td>%s</td></tr>\n"
+ "<tr><th>idle processes</th><td>%d</td></tr>\n"
+ "<tr><th>active processes</th><td>%d</td></tr>\n"
+ "<tr><th>total processes</th><td>%d</td></tr>\n"
+ "</table>",
+ status->accepted_conn, fpm_status_pool, status->pm == PM_STYLE_STATIC ? "static" : "dynamic", status->idle, status->active, status->total);
+
+ spprintf(content_type, 0, "text/html");
+}
+/* }}} */
+
+static void fpm_status_handle_status_json(struct fpm_status_s *status, char **output, char **content_type) /* {{{ */
+{
+ if (!status || !output || !content_type) {
+ return;
+ }
+
+ spprintf(output, 0,
+ "{"
+ "\"accepted conn\":%lu,"
+ "\"pool\":\"%s\","
+ "\"process manager\":\"%s\","
+ "\"idle processes\":%d,"
+ "\"active processes\":%d,"
+ "\"total processes\":%d"
+ "}",
+ status->accepted_conn, fpm_status_pool, status->pm == PM_STYLE_STATIC ? "static" : "dynamic", status->idle, status->active, status->total);
+
+ spprintf(content_type, 0, "application/jsonrequest");
+}
+/* }}} */
+
/* return 0 if it's not the request page
* return 1 if ouput has been set)
* *output unchanged: error (return 500)
* *output changed: no error (return 200)
*/
-int fpm_status_handle_status(char *uri, char **output) /* {{{ */
+int fpm_status_handle_status(char *uri, char *query_string, char **output, char **content_type) /* {{{ */
{
struct fpm_status_s status;
@@ -162,7 +223,7 @@ int fpm_status_handle_status(char *uri, char **output) /* {{{ */
return(0);
}
- if (!output || !fpm_status_shm) {
+ if (!output || !content_type || !fpm_status_shm) {
return(1);
}
@@ -177,16 +238,15 @@ int fpm_status_handle_status(char *uri, char **output) /* {{{ */
return(1);
}
- spprintf(output, 0,
- "accepted conn: %lu\n"
- "pool: %s\n"
- "process manager: %s\n"
- "idle processes: %d\n"
- "active processes: %d\n"
- "total processes: %d\n",
- status.accepted_conn, fpm_status_pool, status.pm == PM_STYLE_STATIC ? "static" : "dynamic", status.idle, status.active, status.total);
+ if (query_string && strstr(query_string, "html")) {
+ fpm_status_handle_status_html(&status, output, content_type);
+ } else if (query_string && strstr(query_string, "json")) {
+ fpm_status_handle_status_json(&status, output, content_type);
+ } else {
+ fpm_status_handle_status_txt(&status, output, content_type);
+ }
- if (!*output) {
+ if (!*output || !content_type) {
zlog(ZLOG_STUFF, ZLOG_ERROR, "[pool %s] unable to allocate status ouput buffer", fpm_status_pool);
return(1);
}
diff --git a/sapi/fpm/fpm/fpm_status.h b/sapi/fpm/fpm/fpm_status.h
index a8bb8ddd53..a8f8487faa 100644
--- a/sapi/fpm/fpm/fpm_status.h
+++ b/sapi/fpm/fpm/fpm_status.h
@@ -24,7 +24,7 @@ void fpm_status_update_accepted_conn(struct fpm_shm_s *shm, unsigned long int ac
void fpm_status_increment_accepted_conn(struct fpm_shm_s *shm);
void fpm_status_set_pm(struct fpm_shm_s *shm, int pm);
int fpm_status_get(int *idle, int *active, int *total, int *pm);
-int fpm_status_handle_status(char *uri, char **output);
+int fpm_status_handle_status(char *uri, char *query_string, char **output, char **content_type);
char* fpm_status_handle_ping(char *uri);
extern struct fpm_shm_s *fpm_status_shm;
diff --git a/sapi/fpm/php-fpm.conf.in b/sapi/fpm/php-fpm.conf.in
index 6d63bbd37c..f73d71bdd9 100644
--- a/sapi/fpm/php-fpm.conf.in
+++ b/sapi/fpm/php-fpm.conf.in
@@ -83,7 +83,7 @@
Sets the status URI to call to obtain php-fpm status page.
If not set, no URI will be recognized as a status page.
- It show text/plain looking like:
+ By default, it returns text/plain looking like:
accepted conn: 12073
pool: default
process manager: static
@@ -98,6 +98,13 @@
"total processes": idle + active
The last three number are uptaded every second.
The "accepted conn" is updated in real time
+ *** Output ***
+ By default it returns text/plain
+ But passing as a query string html or json, it will returns
+ the corresponding output syntax:
+ http://www.foo.bar/status
+ http://www.foo.bar/status?json
+ http://www.foo.bar/status?html
*** WARNING ***
It has to start with a /. It could be named has you want.
It's maybe not a good idea to use .php extension to be certain