]> granicus.if.org Git - php/commitdiff
Add SAPI hook to get the request time if provided by the web server,
authorRasmus Lerdorf <rasmus@php.net>
Tue, 10 Aug 2004 17:40:00 +0000 (17:40 +0000)
committerRasmus Lerdorf <rasmus@php.net>
Tue, 10 Aug 2004 17:40:00 +0000 (17:40 +0000)
otherwise call time(0) on the first call and store it so subsequent
calls will get the same time.  Hook support for Apache1/2 included.

NEWS
main/SAPI.c
main/SAPI.h
sapi/apache/mod_php5.c
sapi/apache2filter/sapi_apache2.c
sapi/apache2handler/sapi_apache2.c

diff --git a/NEWS b/NEWS
index 7e62c1eaded8c4e23dbb8a79f193f7056c81f337..58aa664a3a7d750909e1fd9e89e960c23b243bd7 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,7 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2004, PHP 5.1.0
+- Add SAPI hook to get the current request time. (Rasmus)
 - Fixed bug #29522 (accessing properties without connection) (Georg)
 - Fixed bug #29335 (fetch functions now use MYSQLI_BOTH as default) (Georg)
 - Fixed bug #29311 (calling parent constructor in mysqli). (Georg)
index b1e3488f06529de829d505254de02357bedf73d1..6836a51a05e8ba46cd6acbf38739c6e4196c6671 100644 (file)
@@ -37,6 +37,9 @@
 #ifdef ZTS
 #include "TSRM.h"
 #endif
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
 
 #include "rfc1867.h"
 
@@ -860,7 +863,6 @@ SAPI_API struct stat *sapi_get_stat(TSRMLS_D)
        }
 }
 
-
 SAPI_API char *sapi_getenv(char *name, size_t name_len TSRMLS_DC)
 {
        if (sapi_module.getenv) {
@@ -907,6 +909,15 @@ SAPI_API int sapi_get_target_gid(gid_t *obj TSRMLS_DC)
        }
 }
 
+SAPI_API time_t sapi_get_request_time(TSRMLS_D)
+{
+       if (sapi_module.get_request_time) {
+               return sapi_module.get_request_time(TSRMLS_C);
+       } else {
+               if(!SG(global_request_time)) SG(global_request_time) = time(0);
+               return SG(global_request_time);
+       }
+}
 
 /*
  * Local variables:
index d740eb90610b1efe77067b81bcc59a1190cfb98f..32e69d2e8e89ae9f7503c1136cb3443d37a06cdf 100644 (file)
@@ -122,6 +122,7 @@ typedef struct _sapi_globals_struct {
        long post_max_size;
        int options;
        zend_bool sapi_started;
+       time_t global_request_time;
 } sapi_globals_struct;
 
 
@@ -197,6 +198,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);
 END_EXTERN_C()
 
 struct _sapi_module_struct {
@@ -225,6 +227,7 @@ struct _sapi_module_struct {
 
        void (*register_server_variables)(zval *track_vars_array TSRMLS_DC);
        void (*log_message)(char *message);
+       time_t (*get_request_time)(TSRMLS_D);
 
        char *php_ini_path_override;
 
index 083cc8be565bafa05edefa787a8203562ab36632..ad2f3b35209addf950ab6c44ffdf9d10f17b09da 100644 (file)
@@ -401,6 +401,14 @@ 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)
+{
+       return ((request_rec *)SG(server_context))->request_time;
+}
+/* }}} */
+
 /* {{{ sapi_module_struct apache_sapi_module
  */
 static sapi_module_struct apache_sapi_module = {
@@ -429,6 +437,7 @@ static sapi_module_struct apache_sapi_module = {
 
        sapi_apache_register_server_variables,          /* register server variables */
        php_apache_log_message,                 /* Log message */
+       php_apache_get_request_time,    /* Get request time */
 
        NULL,                                                   /* php.ini path override */
 
index cf6bec19339ebfe560e08f70bdde54f5e8fdbc78..cb4ed06586e95c1fc6a164cebf2d0704fbeee9ac 100644 (file)
@@ -299,6 +299,15 @@ php_apache_disable_caching(ap_filter_t *f)
        return OK;
 }
 
+static time_t
+php_apache_sapi_get_request_time(void)
+{
+       php_struct *ctx = SG(server_context);
+       TSRMLS_FETCH();
+
+       return ctx->r->request_time;
+}
+
 extern zend_module_entry php_apache_module;
 
 static int php_apache2_startup(sapi_module_struct *sapi_module)
@@ -335,6 +344,7 @@ static sapi_module_struct apache2_sapi_module = {
 
        php_apache_sapi_register_variables,
        php_apache_sapi_log_message,                    /* Log message */
+       php_apache_sapi_get_request_time,               /* Get Request Time */
 
        STANDARD_SAPI_MODULE_PROPERTIES
 };
index e7e9571044cc169c8eaaabafcbcce412792a9d96..78d3aa41333f064b3a97c954a16708373f1f012a 100644 (file)
@@ -277,6 +277,13 @@ static void php_apache_sapi_log_message_ex(char *msg, request_rec *r)
        }
 }
 
+static time_t php_apache_sapi_get_request_time(void) {
+       php_struct *ctx = SG(server_context);
+       TSRMLS_FETCH();
+
+       return ctx->r->request_time;
+}
+
 extern zend_module_entry php_apache_module;
 
 static int php_apache2_startup(sapi_module_struct *sapi_module)
@@ -313,6 +320,7 @@ static sapi_module_struct apache2_sapi_module = {
 
        php_apache_sapi_register_variables,
        php_apache_sapi_log_message,                    /* Log message */
+       php_apache_sapi_get_request_time,               /* Request Time */
 
        STANDARD_SAPI_MODULE_PROPERTIES
 };