Hi,

This patch adds apache uptime to phpinfo() page for apache, 
apache2filter and apache2handler SAPIs.

Should I commit, throw it away, change something ?


/Magnus

-- 
Debian is like Suse with yast turned off, just better. :)
 -- Goswin Brederlow
Index: sapi/apache/php_apache.c
===================================================================
RCS file: /repository/php-src/sapi/apache/php_apache.c,v
retrieving revision 1.88
diff -u -r1.88 php_apache.c
--- sapi/apache/php_apache.c	4 Dec 2004 13:47:13 -0000	1.88
+++ sapi/apache/php_apache.c	6 Jan 2005 19:40:41 -0000
@@ -178,9 +178,11 @@
 	extern char *user_name;
 	extern gid_t group_id;
 	extern int max_requests_per_child;
+	time_t uptime;
 
 	serv = ((request_rec *) SG(server_context))->server;
 
+	uptime = time(NULL) - ap_restart_time;
 
 	php_info_print_table_start();
 
@@ -217,6 +219,9 @@
 #endif
 	sprintf(output_buf, "Connection: %d - Keep-Alive: %d", serv->timeout, serv->keep_alive_timeout);
 	php_info_print_table_row(2, "Timeouts", output_buf);
+	sprintf(output_buf, "%ld day(s) %ld hour(s) %ld minute(s) %ld second(s)",
+			uptime / 60 / 60 / 24, uptime / 60 / 60 % 24, uptime / 60 % 60, uptime % 60);
+	php_info_print_table_row(2, "Uptime", output_buf);
 #if !defined(WIN32) && !defined(WINNT)
 /*
 	This block seems to be working on NetWare; But it seems to be showing
Index: sapi/apache2filter/php_functions.c
===================================================================
RCS file: /repository/php-src/sapi/apache2filter/php_functions.c,v
retrieving revision 1.43
diff -u -r1.43 php_functions.c
--- sapi/apache2filter/php_functions.c	23 Oct 2004 13:48:04 -0000	1.43
+++ sapi/apache2filter/php_functions.c	6 Jan 2005 19:40:42 -0000
@@ -40,6 +40,7 @@
 #include "http_main.h"
 #include "util_script.h"
 #include "http_core.h"
+#include "scoreboard.h"
 
 #include "php_apache.h"
 
@@ -330,8 +331,12 @@
 {
 	char *apv = php_apache_get_version();
 	smart_str tmp1 = {0};
+	char tmp[1024];
 	int n;
 	char *p;
+	apr_interval_time_t uptime;
+
+	uptime = (apr_uint32_t) apr_time_sec(apr_time_now() - ap_scoreboard_image->global->restart_time);
 	
 	for (n = 0; ap_loaded_modules[n]; ++n) {
 		char *s = (char *) ap_loaded_modules[n]->name;
@@ -350,6 +355,12 @@
 	if (apv && *apv) {
 		php_info_print_table_row(2, "Apache Version", apv);
 	}
+	apr_snprintf(tmp, sizeof tmp,
+				 "%" APR_TIME_T_FMT " day(s) %" APR_TIME_T_FMT " hour(s) %" APR_TIME_T_FMT
+				 " minute(s) %" APR_TIME_T_FMT " second(s)",
+				 uptime / 60 / 60 / 24, uptime / 60 / 60 % 24, uptime / 60 % 60, uptime % 60);
+	php_info_print_table_row(2, "Uptime", tmp);
+	
 	php_info_print_table_row(2, "Loaded Modules", tmp1.c);
 	smart_str_free(&tmp1);
 	php_info_print_table_end();
Index: sapi/apache2handler/php_functions.c
===================================================================
RCS file: /repository/php-src/sapi/apache2handler/php_functions.c,v
retrieving revision 1.15
diff -u -r1.15 php_functions.c
--- sapi/apache2handler/php_functions.c	23 Oct 2004 13:48:05 -0000	1.15
+++ sapi/apache2handler/php_functions.c	6 Jan 2005 19:40:43 -0000
@@ -42,6 +42,7 @@
 #include "util_script.h"
 #include "http_core.h"
 #include "ap_mpm.h"
+#include "scoreboard.h"
 #if !defined(WIN32) && !defined(WINNT)
 #include "unixd.h"
 #endif
@@ -364,6 +365,9 @@
 #if !defined(WIN32) && !defined(WINNT)
 	AP_DECLARE_DATA extern unixd_config_rec unixd_config;
 #endif
+
+	apr_interval_time_t uptime;
+	uptime = (apr_uint32_t) apr_time_sec(apr_time_now() - ap_scoreboard_image->global->restart_time);
 	
 	for (n = 0; ap_loaded_modules[n]; ++n) {
 		char *s = (char *) ap_loaded_modules[n]->name;
@@ -405,6 +409,12 @@
 				 "Connection: %" APR_TIME_T_FMT " - Keep-Alive: %" APR_TIME_T_FMT, 
 				 apr_time_sec(serv->timeout), apr_time_sec(serv->keep_alive_timeout));
 	php_info_print_table_row(2, "Timeouts", tmp);
+
+	apr_snprintf(tmp, sizeof tmp, 
+				 "%" APR_TIME_T_FMT " day(s) %" APR_TIME_T_FMT " hour(s) %" APR_TIME_T_FMT
+				 " minute(s) %" APR_TIME_T_FMT " second(s)",
+				 uptime / 60 / 60 / 24, uptime / 60 / 60 % 24, uptime / 60 % 60, uptime % 60);
+	php_info_print_table_row(2, "Uptime", tmp);
 	
 	php_info_print_table_row(2, "Virtual Server", (serv->is_virtual ? "Yes" : "No"));
 	php_info_print_table_row(2, "Server Root", ap_server_root);

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to