'How can i measure the time between HTTP REQUEST & HTTP RESPONSE on server side?
So, i have this mobile game and a server. I want to measure the processing time of the server like this: Time (HTTP Response sent) - Time(HTTP request received).
Does anyone can help me ? Is there any tools to do that ?
Solution 1:[1]
If Nginx is used to host PHP, you can use $request_time to record the time between request-received and response-sent:
$request_time – Full request time, starting when NGINX reads the first byte from the client and ending when NGINX sends the last byte of the response body
Please refer to the official document for more information.
If Apache is used to host PHP, you can use %D in log (mod_log_config).
%D - The time taken to serve the request, in microseconds.
Please refer to this article for more information.
Solution 2:[2]
if you just want to view the server response time you can use the chrome dev console and view the time taken for the request-response cycle

if you want to programmatically calculate (assuming you are using a Node backend) the time use :
//receive request
console.time();
// my server code...
console.timeEnd();
//send response
Alternatively, you could use the js Date Object
const timerStart = new Date();
// my server code...
const timerEnd = new Date();
//timerEnd - timerStart (get time in ms)
//send response to client
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | shaochuancs |
| Solution 2 | Ilamuhil Ilavenil |
