Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Create a custom response header called "Duration" that records the time taken to generate the response. Allow this header to be returned only when the request header "Client" with the value of "Get-Duration" is supplied.

share|improve this question

2 Answers 2

You can use SetEnvIf to set an environment variable for requests with Client: Get-Duration and Header to add the time taken to serve these requests.

[root@dev ~]# cat /etc/httpd/conf.d/test.conf
SetEnvIf Client ^Get-Duration$ SET_DURATION 
Header set X-Duration %D env=SET_DURATION

[root@dev ~]# GET -Sed http://localhost/
GET http://localhost/ --> 200 OK
Connection: close
Date: Mon, 14 Sep 2009 15:08:27 GMT
Server: Apache/2.2.3 (Red Hat)
Content-Length: 525
Content-Type: text/html;charset=ISO-8859-1
Client-Date: Mon, 14 Sep 2009 15:08:27 GMT
Client-Peer: 127.0.0.1:80
Client-Response-Num: 1
Title: Index of /

[root@dev ~]# GET -SedH 'Client: Get-Duration' http://localhost/
GET http://localhost/ --> 200 OK
Connection: close
Date: Mon, 14 Sep 2009 15:08:39 GMT
Server: Apache/2.2.3 (Red Hat)
Content-Length: 525
Content-Type: text/html;charset=ISO-8859-1
Client-Date: Mon, 14 Sep 2009 15:08:39 GMT
Client-Peer: 127.0.0.1:80
Client-Response-Num: 1
Title: Index of /
X-Duration: D=540

mod_headers docs on %D:

The time from when the request was received to the time the headers are sent on the wire. This is a measure of the duration of the request. The value is preceded by D=.

It looks D is measured in microseconds, based on this test:

[root@dev ~]# cat /var/www/cgi-bin/sleep.cgi
#!/bin/sh

sleep 1 && echo "Content-type: text/plain" && echo

[root@dev ~]# GET -SedH 'Client: Get-Duration' http://localhost/cgi-bin/sleep.cgi \
| grep Duration
X-Duration: D=1008576

Edit: this approach is only going to make sense if your response is assembled before Apache writes the headers out. If you're using HTTP chunking or have an unbuffered script your timings may be misleading.

share|improve this answer

if u have apache & php on server side you could use apache_request_headers() to read the headers and if matched use header() function to send custom header, here u have some howto from php documentation to read:

but if the time you want to report is total time - processing by apache/php and sending request back - it may be not possible/easy to do - because at the time when php processes the page apache/php is not aware about the time the data will need to be send back to the client.

savecore

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.