From: Ilia Alshanetsky Date: Sat, 6 Nov 2010 17:14:21 +0000 (+0000) Subject: Updated _SERVER['REQUEST_TIME'] to include microsecond precision. X-Git-Tag: php-5.4.0alpha1~191^2~726 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f89effd2a83de2b1d6381f9b9403a8328e0998b6;p=php Updated _SERVER['REQUEST_TIME'] to include microsecond precision. --- diff --git a/NEWS b/NEWS index abf454a5dc..45aace19c8 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,7 @@ - Upgraded bundled sqlite to version 3.7.3. (Ilia) - Upgraded bundled PCRE to version 8.10. (Ilia) +- Updated _SERVER['REQUEST_TIME'] to include microsecond precision. (Ilia) - Added apache compatible functions (apache_child_terminate, getallheaders, apache_request_headers, apache_response_headers) to FastCGI SAPI (Dmitry) - Added caches to eliminate repeatable run-time bindings of functions, classes, diff --git a/main/SAPI.c b/main/SAPI.c index 22be6c2e4d..2cc453c203 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -961,14 +961,19 @@ SAPI_API int sapi_get_target_gid(gid_t *obj TSRMLS_DC) } } -SAPI_API time_t sapi_get_request_time(TSRMLS_D) +SAPI_API double sapi_get_request_time(TSRMLS_D) { if(SG(global_request_time)) return SG(global_request_time); if (sapi_module.get_request_time && SG(server_context)) { SG(global_request_time) = sapi_module.get_request_time(TSRMLS_C); } else { - SG(global_request_time) = time(0); + struct timeval tp = {0}; + if (!gettimeofday(&tp, NULL)) { + SG(global_request_time) = (double)(tp.tv_sec + tp.tv_usec / 1000000.00); + } else { + SG(global_request_time) = (double)time(0); + } } return SG(global_request_time); } diff --git a/main/SAPI.h b/main/SAPI.h index 8c7275a404..9513a45bfb 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -129,7 +129,7 @@ typedef struct _sapi_globals_struct { long post_max_size; int options; zend_bool sapi_started; - time_t global_request_time; + double global_request_time; HashTable known_post_content_types; } sapi_globals_struct; @@ -208,7 +208,7 @@ SAPI_API int sapi_force_http_10(TSRMLS_D); SAPI_API int sapi_get_target_uid(uid_t * TSRMLS_DC); SAPI_API int sapi_get_target_gid(gid_t * TSRMLS_DC); -SAPI_API time_t sapi_get_request_time(TSRMLS_D); +SAPI_API double sapi_get_request_time(TSRMLS_D); SAPI_API void sapi_terminate_process(TSRMLS_D); END_EXTERN_C() diff --git a/main/php_variables.c b/main/php_variables.c index f1744b111e..b8113a66da 100644 --- a/main/php_variables.c +++ b/main/php_variables.c @@ -590,8 +590,8 @@ static inline void php_register_server_variables(TSRMLS_D) /* store request init time */ { zval new_entry; - Z_TYPE(new_entry) = IS_LONG; - Z_LVAL(new_entry) = sapi_get_request_time(TSRMLS_C); + Z_TYPE(new_entry) = IS_DOUBLE; + Z_DVAL(new_entry) = sapi_get_request_time(TSRMLS_C); php_register_variable_ex("REQUEST_TIME", &new_entry, array_ptr TSRMLS_CC); } diff --git a/sapi/apache/mod_php5.c b/sapi/apache/mod_php5.c index 1d858a5bc1..10b30ee5ec 100644 --- a/sapi/apache/mod_php5.c +++ b/sapi/apache/mod_php5.c @@ -438,9 +438,9 @@ static int sapi_apache_get_target_gid(gid_t *obj TSRMLS_DC) /* {{{ php_apache_get_request_time */ -static time_t php_apache_get_request_time(TSRMLS_D) +static double php_apache_get_request_time(TSRMLS_D) { - return ((request_rec *)SG(server_context))->request_time; + return (double) ((request_rec *)SG(server_context))->request_time; } /* }}} */ diff --git a/sapi/apache2filter/sapi_apache2.c b/sapi/apache2filter/sapi_apache2.c index 5aa798c53d..c63ada0ba1 100644 --- a/sapi/apache2filter/sapi_apache2.c +++ b/sapi/apache2filter/sapi_apache2.c @@ -308,10 +308,10 @@ php_apache_disable_caching(ap_filter_t *f) return OK; } -static time_t php_apache_sapi_get_request_time(TSRMLS_D) +static double php_apache_sapi_get_request_time(TSRMLS_D) { php_struct *ctx = SG(server_context); - return apr_time_sec(ctx->r->request_time); + return apr_time_as_msec(ctx->r->request_time); } extern zend_module_entry php_apache_module; diff --git a/sapi/apache2handler/sapi_apache2.c b/sapi/apache2handler/sapi_apache2.c index f8eb2d47ea..de9228069b 100644 --- a/sapi/apache2handler/sapi_apache2.c +++ b/sapi/apache2handler/sapi_apache2.c @@ -335,10 +335,10 @@ static void php_apache_sapi_log_message_ex(char *msg, request_rec *r TSRMLS_DC) } } -static time_t php_apache_sapi_get_request_time(TSRMLS_D) +static double php_apache_sapi_get_request_time(TSRMLS_D) { php_struct *ctx = SG(server_context); - return apr_time_sec(ctx->r->request_time); + return apr_time_as_msec(ctx->r->request_time); } extern zend_module_entry php_apache_module; diff --git a/sapi/nsapi/nsapi.c b/sapi/nsapi/nsapi.c index eaa20f7fff..5847c6fe1c 100644 --- a/sapi/nsapi/nsapi.c +++ b/sapi/nsapi/nsapi.c @@ -784,7 +784,7 @@ static void nsapi_log_message(char *message TSRMLS_DC) } } -static time_t sapi_nsapi_get_request_time(TSRMLS_D) +static double sapi_nsapi_get_request_time(TSRMLS_D) { return REQ_TIME( ((nsapi_request_context *)SG(server_context))->rq ); }