Is there a way to specify a condition in apache httpd access_log to persist only requests which took longer than 500ms to process?

  • I'm confused. Are you trying to just create a log of slow requests or are you trying to make the server hang on to the connection if it takes a long time to process? If the latter, then you may want to look up the network term KeepAlive Jul 22, 2017 at 15:39
  • I want to get a list of HTTP requests which tool longer than expected. I need it in order to create a plan of website optimization.
    – Anthony
    Jul 22, 2017 at 17:06

1 Answer 1


The CustomLog directive allows you to set a condition (in an optional 3rd argument) that is used to control when the request is logged. (On Apache 2.4+ this can take the form of an Apache Expression.) However, this condition is generally based on a property of the request (file type, request header, etc.), rather than something that is associated with the response. (Although it does seem possible to create a condition based on the HTTP response status, as this is explicitly made available in the REQUEST_STATUS server variable.)

However, I don't see a way to create a conditon based on the server response time. (?)

A workaround might be to specifically include this information in your access log using the format string %msT (if you specifically want this logged as milliseconds) in a custom log format. You can then filter this information using a log file analyzer.

  • %T - The time taken to serve the request, in seconds.

  • %{UNIT}T - The time taken to serve the request, in a time unit given by UNIT. Valid units are ms for milliseconds, us for microseconds, and s for seconds. Using s gives the same result as %T without any format; using us gives the same result as %D. Combining %T with a unit is available in 2.4.13 and later.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.