I wrote a little script to diagnose the connection time of my website, and here is the result:
Lookup time: 0.6454ms
Connect time: 1.1611ms
Pretransfer time: 1.1615ms
Redirect time: 0ms
Time to 1st Byte time: 43.397ms
Total time: 43.445ms
The code used is as follow:
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if(curl_exec($ch) !== false) {
$info = curl_getinfo($ch);
echo 'Lookup time: ' . "\t\t" . ($info['namelookup_time'] * 1000) . 'ms' . PHP_EOL;
echo 'Connect time: ' . "\t\t" . ($info['connect_time'] * 1000) . 'ms' . PHP_EOL;
echo 'Pretransfer time: ' . "\t" . ($info['pretransfer_time']) . 'ms' . PHP_EOL;
echo 'Redirect time: ' . "\t\t" . ($info['redirect_time'] * 1000) . 'ms' . PHP_EOL;
echo 'Time to 1st Byte time: ' . "\t" . ($info['starttransfer_time'] * 1000) . 'ms' . PHP_EOL;
echo 'Total time: ' . "\t\t" . ($info['total_time'] * 1000) . 'ms' . PHP_EOL;
} else {
echo 'Error: ' . curl_error($ch);
}
curl_close($ch);
I don't quite understand the result above.
Output of curl_getinfo($ch)
:
Array
(
[url] => http://www.example.com/apply.php
[content_type] => text/html
[http_code] => 302
[header_size] => 412
[request_size] => 88
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.043445
[namelookup_time] => 0.006454
[connect_time] => 0.011611
[pretransfer_time] => 0.011615
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => 0
[upload_content_length] => 0
[starttransfer_time] => 0.043397
[redirect_time] => 0
[certinfo] => Array
(
)
[redirect_url] => http://www.example.com/index.php
)
curl_getinfo — Get information regarding a specific transfer.
To make a GET request using Curl, run the curl command followed by the target URL. Curl automatically selects the HTTP GET request method unless you use the -X, --request, or -d command-line option.
#include <curl/curl.h> CURLcode curl_easy_getinfo (CURL *curl, CURLINFO info, ... ); Request internal information from the curl session with this function. The third argument MUST be a pointer to a long, a pointer to a char *, a pointer to a struct curl_slist * or a pointer to a double (as this documentation describes further down).
While the time breakdown from cURL can be useful, it doesn’t breakdown all of the various times for a request. For instance WebPageTest will report times for: SSL延迟有多大? – City Hunter […] Timing Analysis section.
curl_getinfo ( CurlHandle $handle, ?int $option = null ): mixed Gets information about the last transfer. A cURL handle returned by curl_init ().
curl_getinfo ( CurlHandle $handle, ?int $option = null ): mixed Gets information about the last transfer. A cURL handle returned by curl_init (). CURLINFO_HTTP_CODE - The last response code. As of cURL 7.10.8, this is a legacy alias of CURLINFO_RESPONSE_CODE
Don't round time for any thorough analysis of a request. 0ms
and 0.5ms
are ages apart for computers; read the raw numbers to avoid confusion.
1) If an HTTP request returns a single resource (as opposed to a complete web page), TTFB and Total Time are both the same things, unless the amount of data returned by the server was considerably larger.
2) Yes it is cumulative. Increase the amount of data returned by the URL and you will see that the transfer time will also increase from 0ms
3) Time spent waiting for the server to respond after it accepted the request
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With