fat Tue, 22 Dec 2009 16:08:53 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=292487
Log:
Add html and json syntax to status page
Changed paths:
U php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fpm_main.c
U php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fpm_status.c
U php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fpm_status.h
U php/php-src/branches/PHP_5_3_FPM/sapi/fpm/php-fpm.conf.in
Modified: php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fpm_main.c
===================================================================
--- php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fpm_main.c 2009-12-22
15:56:44 UTC (rev 292486)
+++ php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fpm_main.c 2009-12-22
16:08:53 UTC (rev 292487)
@@ -1765,7 +1765,7 @@
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 @@
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");
}
Modified: php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fpm_status.c
===================================================================
--- php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fpm_status.c 2009-12-22
15:56:44 UTC (rev 292486)
+++ php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fpm_status.c 2009-12-22
16:08:53 UTC (rev 292487)
@@ -144,12 +144,73 @@
}
/* }}} */
+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 @@
return(0);
}
- if (!output || !fpm_status_shm) {
+ if (!output || !content_type || !fpm_status_shm) {
return(1);
}
@@ -177,16 +238,15 @@
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);
}
Modified: php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fpm_status.h
===================================================================
--- php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fpm_status.h 2009-12-22
15:56:44 UTC (rev 292486)
+++ php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fpm_status.h 2009-12-22
16:08:53 UTC (rev 292487)
@@ -24,7 +24,7 @@
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;
Modified: php/php-src/branches/PHP_5_3_FPM/sapi/fpm/php-fpm.conf.in
===================================================================
--- php/php-src/branches/PHP_5_3_FPM/sapi/fpm/php-fpm.conf.in 2009-12-22
15:56:44 UTC (rev 292486)
+++ php/php-src/branches/PHP_5_3_FPM/sapi/fpm/php-fpm.conf.in 2009-12-22
16:08:53 UTC (rev 292487)
@@ -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
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php