]> granicus.if.org Git - php/commitdiff
Updated _SERVER['REQUEST_TIME'] to include microsecond precision.
authorIlia Alshanetsky <iliaa@php.net>
Sat, 6 Nov 2010 17:14:21 +0000 (17:14 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Sat, 6 Nov 2010 17:14:21 +0000 (17:14 +0000)
NEWS
main/SAPI.c
main/SAPI.h
main/php_variables.c
sapi/apache/mod_php5.c
sapi/apache2filter/sapi_apache2.c
sapi/apache2handler/sapi_apache2.c
sapi/nsapi/nsapi.c

diff --git a/NEWS b/NEWS
index abf454a5dc04e16ad731b5c5434e86f0824a1ced..45aace19c86788dd00a95f804c0be4a90711e19a 100644 (file)
--- 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,
index 22be6c2e4daddcbdd0c2e89c23a6e01f22987b2c..2cc453c203dd22d705ba528edec6a739885ecb73 100644 (file)
@@ -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);
 }
index 8c7275a404a0bb1c39cf922b5ee19869b1681c6b..9513a45bfb1350aabab61aa2cd193ddf2878922e 100644 (file)
@@ -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()
 
index f1744b111e5e5f8cc96d17cb288d4a0fd52d14d2..b8113a66da84e25f387f7355d35f1fd4632d4e26 100644 (file)
@@ -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);
        }
 
index 1d858a5bc1a16f3f582d4d18190251e0954a29a2..10b30ee5ec28bcbf61bb7eadb2355e8e31b3944f 100644 (file)
@@ -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;
 }
 /* }}} */
 
index 5aa798c53de19079c1aef0342057900a1982910c..c63ada0ba13a0f577831f9e8a0568455004feca7 100644 (file)
@@ -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;
index f8eb2d47ea6af712fb131efbb62304e4d40bde22..de9228069b0b983b8a4a6da31f1af01254d74bb7 100644 (file)
@@ -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;
index eaa20f7ffff30c82990f3b50626a07b820dfb596..5847c6fe1c458cd9ea0a784e52df5fcd3684a5d0 100644 (file)
@@ -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 );
 }