From: Dmitry Stogov Date: Thu, 25 Oct 2007 05:39:06 +0000 (+0000) Subject: Added CGI SAPI -T option, to measure execution time of script repeated several times. X-Git-Tag: RELEASE_1_3_1~812 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6f7b738b712f234ec34a1e905572530bc277c8ca;p=php Added CGI SAPI -T option, to measure execution time of script repeated several times. --- diff --git a/NEWS b/NEWS index d7da084b1e..b5b4dc27db 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,8 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 20??, PHP 5.3.0 +- Added CGI SAPI -T option, to measure execution time of script repeated + several times. (Dmitry) - Added icon format support to getimagesize(). (Scott) - Added LDAP_OPT_NETWORK_TIMEOUT option for ldap_set_option() to allow setting network timeout (FR #42837). (Jani) diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index 794ebd8c15..e1d53e899e 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -137,6 +137,7 @@ static const opt_struct OPTIONS[] = { {'?', 0, "usage"},/* help alias (both '?' and 'usage') */ {'v', 0, "version"}, {'z', 1, "zend-extension"}, + {'T', 1, "timing"}, {'-', 0, NULL} /* end of args */ }; @@ -758,7 +759,8 @@ static void php_cgi_usage(char *argv0) " -s Display colour syntax highlighted source.\n" " -v Version number\n" " -w Display source with stripped comments and whitespace.\n" - " -z Load Zend extension .\n", + " -z Load Zend extension .\n" + " -T Measure execution time of script repeated times.\n", prog, prog); } /* }}} */ @@ -1257,6 +1259,9 @@ int main(int argc, char *argv[]) char *bindpath = NULL; int fcgi_fd = 0; fcgi_request request; + int repeats = 1; + int benchmark = 0; + struct timeval start, end; #ifndef PHP_WIN32 int status = 0; #endif @@ -1533,6 +1538,11 @@ consult the installation file that came with this distribution, or visit \n\ zend_first_try { while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 1, 2)) != -1) { switch (c) { + case 'T': + benchmark = 1; + repeats = atoi(php_optarg); + gettimeofday(&start, NULL); + break; case 'h': case '?': fcgi_shutdown(); @@ -1907,8 +1917,18 @@ fastcgi_request_done: } } - if (!fastcgi) + if (!fastcgi) { + if (benchmark) { + repeats--; + if (repeats > 0) { + script_file = NULL; + php_optind = orig_optind; + php_optarg = orig_optarg; + continue; + } + } break; + } /* only fastcgi will get here */ requests++; @@ -1938,6 +1958,21 @@ fastcgi_request_done: } zend_end_try(); out: + if (benchmark) { + int sec; + int usec; + + gettimeofday(&end, NULL); + sec = (int)(end.tv_sec - start.tv_sec); + if (end.tv_usec >= start.tv_usec) { + usec = (int)(end.tv_usec - start.tv_usec); + } else { + sec -= 1; + usec = (int)(end.tv_usec + 1000000 - start.tv_usec); + } + fprintf(stderr, "\nElapsed time: %d.%06d sec\n", sec, usec); + } + SG(server_context) = NULL; php_module_shutdown(TSRMLS_C); sapi_shutdown();