Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is nginx's $request_time and why is it a lot more than php-fpm execution time?

Tags:

php

nginx

Background: It is the objective of my project is to create a very fast responding website. There are only very few pages, many of them are simply 302 redirects.

In Nginx, I'm logging here $request_time.

In PHP, I'm logging the microtime of the start of the request and just before it exits.

php-fpm (php 5.3.27) and nginx (1.4.4) run on the same machine, there is no database (just writing to a Beanstalkd queue), there are no complicated nginx configurations.

Problem: There is a massive discrepancy between the PHP execution time and Nginx's $request_time. The $request_time is generally 0.5 seconds but during some hours it's more like 3 seconds on average. PHP's execution time is always between 0.008 seconds and 0.02 seconds (using PhalconPHP).

Question: Why could there be such a big discrepancy? Perhaps I don't fully understand what $request_time is, or maybe my webservers have some problematic configuration? I'd be happy to provide more information about the environment.

like image 898
hdeh Avatar asked Dec 05 '13 23:12

hdeh


People also ask

Does nginx require PHP-FPM?

Nginx is the DevOps community's most beloved http web server. And developers love the PHP programming language because it enables them to quickly build and deploy interactive websites. As such, it's no wonder that so many sys admins need to configure Nginx, PHP and PHP-FPM on both Linux and Windows servers.

What is PHP-FPM in nginx?

PHP-FPM (FastCGI Process Manager) is an alternative to FastCGI implementation of PHP with some additional features useful for sites with high traffic. It is the preferred method of processing PHP pages with NGINX and is faster than traditional CGI based methods such as SUPHP or mod_php for running a PHP script.

What is request_ time in nginx?

$request_time. request processing time in seconds with a milliseconds resolution; time elapsed between the first bytes were read from the client and the log write after the last bytes were sent to the client.

What is PHP-FPM stackoverflow?

PHP-FPM compiles and executes the PHP script, sending the output back to the web server. Currently i am using nginx as a proxy server, the plan is to send all request that require dynamic content to PHP-fpm from nginx.


1 Answers

$request_time is the time from the first byte sent, to the time everything is closed up and logging has been completed. If you look at your nginx logs and the microtime you are logging, how close are they in terms of starting times? For the ones where the request_time was closer to 3 seconds, and the php execution time was say 0.02 seconds, if you extrapolate the request start time and compare that to the microtime inside php, are they close, or did nginx need to wait a second or 2 (perhaps for a php process to free up, etc..). It would probably be interesting to also log the $upstream_response_time to see how that compares.

like image 120
Doon Avatar answered Sep 16 '22 17:09

Doon