Created
December 3, 2012 20:31
-
-
Save mtourne/4197759 to your computer and use it in GitHub Desktop.
Expose a $request_time in msec to Nginx core
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* inspired from ngx_http_log_module.c:ngx_http_log_request_time() */ | |
static ngx_int_t | |
ngx_http_request_time(ngx_http_request_t *r, | |
ngx_http_variable_value_t *v, | |
uintptr_t data) { | |
ngx_time_t *tp; | |
ngx_msec_int_t ms; | |
tp = ngx_timeofday(); | |
ms = (ngx_msec_int_t) | |
((tp->sec - r->start_sec) * 1000 + (tp->msec - r->start_msec)); | |
ms = ngx_max(ms, 0); | |
v->data = ngx_pnalloc(r->pool, NGX_TIME_T_LEN + 4); | |
if (v->data == NULL) { | |
return NGX_ERROR; | |
} | |
v->valid = 1; | |
v->no_cacheable = 0; | |
v->not_found = 0; | |
v->len = ngx_snprintf(v->data, NGX_TIME_T_LEN + 4, | |
"%T.%03M", ms / 1000, ms % 1000) - v->data; | |
return NGX_OK; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you would probably need to make this part of a module, but if I were you I would explore if this data isn't already accessible via the Lua api found in OpenResty.