CURL request terms, getting details from curl_getinfo ()

I wrote a little script to diagnose the connection time of my site, 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 follows:

$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 do not quite understand the result above.

  • Why is the time from first to first byte (TTFB) equal to Total Time?
  • Is the above sync summarized? If so, is the transmission time 0ms?
  • What does Pretransfer time mean?

Conclusion 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
)
+4
source share
2 answers

Do not round the time for a thorough analysis of the request. 0msand 0.5msages for computers; read raw numbers to avoid confusion.

1) HTTP- ( -), TTFB Total Time , , , .

2) , . , URL-, , 0ms

3)

+1
  • Time to First Byte (TTFB) Total Time?

. , .

  • ? , 0?

, . , .

  • Pretransfer?

Pretransfer time .

Curl GetInfo

.

.

  • CURLINFO_SIZE_UPLOAD -
  • CURLINFO_SIZE_DOWNLOAD -
  • CURLINFO_SPEED_DOWNLOAD -
  • CURLINFO_SPEED_UPLOAD -

, .

Update:

, . , .

0

Source: https://habr.com/ru/post/1650130/


All Articles