Skip to content

Commit e2d05bf

Browse files
committed
Allow get_request_time() hook to fail
In particular, this allows using the hook without server_context. The apache2handler implementation now checks that server_context is available itself, as that's the implementation that cares about it.
1 parent 13fa90f commit e2d05bf

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

main/SAPI.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,9 +1073,8 @@ SAPI_API double sapi_get_request_time(void)
10731073
{
10741074
if(SG(global_request_time)) return SG(global_request_time);
10751075

1076-
if (sapi_module.get_request_time && SG(server_context)) {
1077-
SG(global_request_time) = sapi_module.get_request_time();
1078-
} else {
1076+
if (!sapi_module.get_request_time
1077+
|| sapi_module.get_request_time(&SG(global_request_time)) == FAILURE) {
10791078
struct timeval tp = {0};
10801079
if (!gettimeofday(&tp, NULL)) {
10811080
SG(global_request_time) = (double)(tp.tv_sec + tp.tv_usec / 1000000.00);

main/SAPI.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ struct _sapi_module_struct {
236236

237237
void (*register_server_variables)(zval *track_vars_array);
238238
void (*log_message)(const char *message, int syslog_type_int);
239-
double (*get_request_time)(void);
239+
zend_result (*get_request_time)(double *request_time);
240240
void (*terminate_process)(void);
241241

242242
char *php_ini_path_override;

sapi/apache2handler/sapi_apache2.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,15 @@ static void php_apache_sapi_log_message_ex(const char *msg, request_rec *r)
363363
}
364364
}
365365

366-
static double php_apache_sapi_get_request_time(void)
366+
static zend_result php_apache_sapi_get_request_time(double *request_time)
367367
{
368368
php_struct *ctx = SG(server_context);
369-
return ((double) ctx->r->request_time) / 1000000.0;
369+
if (!ctx) {
370+
return FAILURE;
371+
}
372+
373+
*request_time = ((double) ctx->r->request_time) / 1000000.0;
374+
return SUCCESS;
370375
}
371376

372377
extern zend_module_entry php_apache_module;

0 commit comments

Comments
 (0)