--- php5-5.2.0.orig/sapi/cgi/cgi_main.c	2009-01-14 20:54:20.000000000 -0800
+++ php5-5.2.0/sapi/cgi/cgi_main.c	2009-01-14 21:10:44.000000000 -0800
@@ -55,6 +55,7 @@
 #if HAVE_SYS_WAIT_H
 #include <sys/wait.h>
 #endif
+#include <sys/resource.h>
 #include "zend.h"
 #include "zend_extensions.h"
 #include "php_ini.h"
@@ -1033,6 +1034,12 @@
 	char *redirect_status_env = NULL;
 #endif
 
+	struct rusage start_time;
+	struct rusage end_time;
+	char *http_host = NULL;
+	char *request_uri = NULL;
+	double elapsed_time;
+
 /* end of temporary locals */
 #ifdef ZTS
 	zend_compiler_globals *compiler_globals;
@@ -1416,6 +1423,8 @@
 		while (!fastcgi || fcgi_accept_request(&request) >= 0) {
 #endif
 
+		getrusage(RUSAGE_SELF, &start_time);
+
 #if PHP_FASTCGI
 		SG(server_context) = (void *) &request;
 #else
@@ -1751,6 +1760,22 @@
 
 		}
 
+		if (0 == access("/php-log-cpu-time", F_OK))
+		{
+			getrusage(RUSAGE_SELF, &end_time);
+			http_host = sapi_cgibin_getenv((char *) "HTTP_HOST", sizeof("HTTP_HOST")-1 TSRMLS_CC);
+			request_uri = sapi_cgibin_getenv((char *) "REQUEST_URI", sizeof("REQUEST_URI")-1 TSRMLS_CC);
+			elapsed_time =
+				(end_time.ru_utime.tv_sec - start_time.ru_utime.tv_sec) +
+				((end_time.ru_utime.tv_usec - start_time.ru_utime.tv_usec) / 1000000.0) +
+				(end_time.ru_stime.tv_sec - start_time.ru_stime.tv_sec) +
+				((end_time.ru_stime.tv_usec - start_time.ru_stime.tv_usec) / 1000000.0);
+			if (http_host && request_uri)
+			{
+				fprintf(stderr, "PHP CPU time for \"%s%s\": %0.3f seconds\n", http_host, request_uri, elapsed_time);
+			}
+		}
+
 #if PHP_FASTCGI
 			if (!fastcgi) break;
 			/* only fastcgi will get here */
Only in php5-5.2.0.orig/sapi/cgi: cgi_main.c.orig
