# $request\_time meaning

**URL:** <https://www.ruby-forum.com/t/request-time-meaning/214101>\
**Category:** NGINX\
**Created:** [November 21, 2011, 7:42pm UTC](https://www.ruby-forum.com/t/request-time-meaning/214101 "2011-11-21T19:42:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [November 21, 2011, 7:42pm UTC](https://www.ruby-forum.com/t/request-time-meaning/214101/1 "2011-11-21T19:42:17Z")

</div>

Hi,  
How is the $request\_time calculated in the case of a proxied request.  
I’m  
interested especially in the case where the resource is stale in cache.

Thanks

---

<div class="post-metadata">

**Author:** ![Calin\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/3be4f8/32.png) [@Calin\_D](https://www.ruby-forum.com/u/Calin_D)\
**Post date:** [November 21, 2011, 7:56pm UTC](https://www.ruby-forum.com/t/request-time-meaning/214101/2 "2011-11-21T19:56:31Z")

</div>

Hello!

On Mon, Nov 21, 2011 at 08:41:15PM +0200, Calin D. wrote:

> Hi,  
> How is the $request\_time calculated in the case of a proxied request. I’m  
> interested especially in the case where the resource is stale in cache.

$request\_time is always time since start of the request (when  
first bytes are read from client) till end of the request (when  
last bytes are sent to client and logging happens).

Maxim D.

---

<div class="post-metadata">

**Author:** ![Calin\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/3be4f8/32.png) [@Calin\_D](https://www.ruby-forum.com/u/Calin_D)\
**Post date:** [November 22, 2011, 10:53pm UTC](https://www.ruby-forum.com/t/request-time-meaning/214101/3 "2011-11-22T22:53:20Z")

</div>

So the time spent doing a post\_action is added to $request\_time or not?

---

<div class="post-metadata">

**Author:** ![Calin\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/3be4f8/32.png) [@Calin\_D](https://www.ruby-forum.com/u/Calin_D)\
**Post date:** [November 22, 2011, 11:45pm UTC](https://www.ruby-forum.com/t/request-time-meaning/214101/4 "2011-11-22T23:45:13Z")

</div>

> > On Mon, Nov 21, 2011 at 08:41:15PM +0200, Calin D. wrote:  
> > On Mon, Nov 21, 2011 at 20:55, Maxim D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
> > On Tue, Nov 22, 2011 at 11:52:29PM +0200, Calin D. wrote:

Hi there,

> > > How is the $request\_time calculated in the case of a proxied request. I’m  
> > > interested especially in the case where the resource is stale in cache.
> > 
> > $request\_time is always time since start of the request (when  
> > first bytes are read from client) till end of the request (when  
> > last bytes are sent to client and logging happens).

> So the time spent doing a post\_action is added to $request\_time or not?

It seems straightforward enough to test.

Define a post\_action in a location of (for example) a php script which  
does sleep(3), then see if $request\_time is 3 seconds bigger in that  
location than elsewhere.

When I try it in a location which just serves static files, I do see  
$request\_time = 3.002 in access.log.

You can do the same in your stale-in-cache location.

Good luck,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Calin\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/3be4f8/32.png) [@Calin\_D](https://www.ruby-forum.com/u/Calin_D)\
**Post date:** [November 23, 2011, 10:58am UTC](https://www.ruby-forum.com/t/request-time-meaning/214101/5 "2011-11-23T10:58:17Z")

</div>

Hello!

On Tue, Nov 22, 2011 at 11:52:29PM +0200, Calin D. wrote:

> So the time spent doing a post\_action is added to $request\_time or not?

Added.

In general, post\_action is a dirty hack which works in context of  
a request. It delays all processing of the request (i.e. logging)  
as well as processing of furhter requests in the connection in  
question (if any). This is one of the reasons why post\_action  
isn’t documented, BTW.

Maxim D.

> >

---

<div class="post-metadata">

**Author:** ![Calin\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/3be4f8/32.png) [@Calin\_D](https://www.ruby-forum.com/u/Calin_D)\
**Post date:** [November 23, 2011, 12:26pm UTC](https://www.ruby-forum.com/t/request-time-meaning/214101/6 "2011-11-23T12:26:42Z")

</div>

So it is safe to use post\_action then?  
I’m relying on it to serve cached response for users and update cache  
entry  
in background if needed, so that users get most of the time a cache hit.

Is there a cleaner way to do this?

---

<div class="post-metadata">

**Author:** ![Calin\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/3be4f8/32.png) [@Calin\_D](https://www.ruby-forum.com/u/Calin_D)\
**Post date:** [November 23, 2011, 1:40pm UTC](https://www.ruby-forum.com/t/request-time-meaning/214101/7 "2011-11-23T13:40:26Z")

</div>

Hello!

On Wed, Nov 23, 2011 at 01:25:46PM +0200, Calin D. wrote:

> So it is safe to use post\_action then?  
> I’m relying on it to serve cached response for users and update cache entry  
> in background if needed, so that users get most of the time a cache hit.

It’s not expected to cause crashes and/or protocol violations. It  
may have unexpected side effects though (e.g. it delays processing  
of further requests in the connection, as I alredy outlined  
below).

> Is there a cleaner way to do this?

The way I would recommend is to use "tail -F /path/to/log |

". Maxim D. \> \> \> \> \> \> \> \> \> $request\_time is always time since start of the request (when \> \> \> \> \> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ \> \> \> nginx mailing list \> \> \> removed\_email\_address@domain.invalid \> \> \> http://mailman.nginx.org/mailman/listinfo/nginx \> \> \> \> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ \> \> nginx mailing list \> \> removed\_email\_address@domain.invalid \> \> http://mailman.nginx.org/mailman/listinfo/nginx \> \>
