How to get all kinds of response time of the site
This article mainly explains "how to get all kinds of response time of the site". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought. Let's study and learn "how to get all kinds of response time of the site"!
Sometimes, in order to test the network, you need to return the time spent in each phase, such as the time spent parsing DNS, the time it takes to establish a connection, the time it takes from establishing the connection to preparing for transmission, the time from establishing the connection to the start of the transmission, the whole process, the amount of data downloaded, the download speed, the amount of data uploaded, the upload speed, and so on. The following script gets the above information:
The code is as follows:
# #
# author: www.ttlsa.com #
# QQ group: 39514058 #
# E-mail: service@ttlsa.com #
# #
Use strict
Use Data::Dumper
Use WWW::Curl::Easy
If (! @ ARGV) {
Print "Usaging: $0 url\ n"
Print "For example: $0 www.ttlsa.com\ n"
Exit
}
My $curl = new WWW::Curl::Easy
Open my $response_body, "> / dev/null"
$curl- > setopt (CURLOPT_HEADER,1)
$curl- > setopt (CURLOPT_URL, $ARGV [0])
$curl- > setopt (CURLOPT_WRITEDATA,\ $response_body)
$curl- > perform
My $err = $curl- > errbuf
If (! $err) {
My $st = & getTime
My $http_code = $curl- > getinfo (CURLINFO_RESPONSE_CODE)
My $http_dns_time = $curl- > getinfo (CURLINFO_NAMELOOKUP_TIME)
My $http_conn_time = $curl- > getinfo (CURLINFO_CONNECT_TIME)
# my $http_APP_time = $curl- > getinfo (CURLINFO_APPCONNECT_TIME)
My $http_PRE_TRAN_time = $curl- > getinfo (CURLINFO_PRETRANSFER_TIME)
My $http_START_TRAN_time = $curl- > getinfo (CURLINFO_STARTTRANSFER_TIME)
My $http_TOTAL_time = $curl- > getinfo (CURLINFO_TOTAL_TIME)
My $http_SIZE_DOWN = $curl- > getinfo (CURLINFO_SIZE_DOWNLOAD)
My $http_SPEED_DOWN = $curl- > getinfo (CURLINFO_SPEED_DOWNLOAD)
Printf "local_time:% s, http_code:% d, dns_time:% .3fms, conn_time:% .3fms, pre_tran_time:% .3fms, start_tran_time:% .3fms, total_time:% .3fms, size_download:% dB, speed_download:% dB/s", ($st,$http_code,$http_dns_time,$http_conn_time,$http_PRE_TRAN_time,$http_START_TRAN_time,$http_TOTAL_time $http_SIZE_DOWN,$http_SPEED_DOWN)
Write
Format STDOUT_TOP=
Details of various response times of the site-@ | |
$%
=
+- -+
| | Local time | status | DNS resolution time | connection establishment time | time from connection establishment to preparation for transmission | time from connection establishment to start transmission | whole process time | amount of downloaded data | average download speed | |
+- -+
.
Format STDOUT=
| @