Add SAPI hook to get the request time if provided by the web server,

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.
This commit is contained in:
Rasmus Lerdorf 2004-08-10 17:40:00 +00:00
parent 426443cc18
commit cad60c3760
6 changed files with 43 additions and 1 deletions

1
NEWS
View File

@ -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)

View 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:

View 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;

View 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 */

View 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
};

View 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
};