Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Curl gets the response time of the website

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Curl gets the response time of the website

0. problem

There is always feedback that it is slow to open a certain page.

But they don't know exactly where the slowness lies.

Same question.

When we access the interface of the external business

It often feels slow.

But I just don't know where the slow is.

1. Analysis.

When we open a web page

For a person who doesn't need to think about technology.

The imaginary picture should be

We asked the browser for something through the address bar.

Then the browser goes to the corresponding server to get the corresponding file through the address provided by us.

Then the content is displayed to us according to the server's response.

From the perspective of an operator

Maybe you can't imagine it so simply and rudely.

Otherwise, you may never be able to confirm where the problem is.

Keep it simple and sum it up.

1. When we open the browser and enter www.qq.com in the address bar

The browser will first parse the corresponding network address of the www.qq.com according to the browser cache, computer cache, computer hosts file, and DNS service, and the process will take different time depending on where it is parsed.

Use browser cache and computer cache

The result returned is the fastest, but it may not be up to date, or it may be wrong.

The priority of resolving domain names through hosts files is higher than that of DNS services

We can also modify the resolution results of some domain names in hosts.

two。 After obtaining the corresponding IP of the domain name, the browser begins to make a three-way handshake with the server to connect.

3. The browser initiates a service request to the server after establishing a connection with it

4. After the request is processed internally by the server, the processing result is sent to the browser

5. The browser parses the results sent by the server and then displays them to the user.

The above briefly describes the process of the browser making a service request with the server

Any one of these links that takes too long will affect the speed at which users can visit the site.

2.Curl acquires relevant data

Use cur-w/--write-out l to get relevant data

Several key parameters:

The last URL obtained by url_effective.

The response code returned by the last HTTP (S) or FTP (S) operation of http_code. The response_code added in version 7.18.2 displays the same information.

The numeric code found by http_connect in the response (from the proxy) to the last CONNECT request of cURL. (added in version 7.12.4)

The time (in seconds) spent on all time_total operations. Accurate to milliseconds.

The elapsed time (in seconds) from the start of time_namelookup to the completion of domain name resolution.

The time, in seconds, taken by time_connect TCP to connect to a remote host (or proxy server).

The time, in seconds, taken to connect / shake hands with a remote host, such as time_appconnect SSL/SSH/. (added in version 7.19.0)

The time, in seconds, spent by time_pretransfer from the start to the time the file is about to be transferred. Includes all pre-transfer commands and negotiations for the specified protocol.

The time, in seconds, of all time_redirect redirection steps, including packet domain name resolution, connection, pre-transfer, and transmission before the start of the final transaction. Time_redirect shows the full execution time of multiple orientations. (added in version 7.12.3)

The time, in seconds, before the first byte of the time_starttransfer will be transmitted.

This includes the time required by the time_pretransfer and the server to calculate the results.

Total number of bytes downloaded by size_download.

Total number of bytes uploaded by size_upload.

The total number of bytes of header downloaded by size_header.

The total number of bytes of HTTP requests sent by size_request.

The average download speed of a successful speed_download curl download.

The average upload speed of successful uploads by speed_upload curl.

3. Get the time-consuming information of the request

For a specific request, the time consumption of each link can be obtained through curl.

For example, the time-consuming of domain name resolution, the time of establishing connection, the time-consuming of server processing, and the total time-consuming.

Material of a domestic partner

Curl-o / dev/null-s-w "http_code:% {http_code}\ nhttp_connect:% {http_connect}\ ncontent_type:% {content_type}\ ntime_dns:% {time_namelookup}\ ntime_redirect:% {time_redirect}\ ntime_pretransfer:% {time_pretransfer}\ ntime_connect:% {time_starttransfer}\ ntime_total:% {time_total}:\ nspeed_download:% {speed _ download}\ n "" http://di.adsame.com/flv_test/20161107143341_231.jpg";

Http_code: 200

Http_connect:000

Content_type:p_w_picpath/jpeg

Time_dns:0.005

Time_redirect:0.000

Time_pretransfer:0.013

Time_connect:0.013

Time_starttransfer:0.021

Time_total:0.029:

Speed_download:441815.000

Apple official website picture material

Curl-o / dev/null-s-w "http_code:% {http_code}\ nhttp_connect:% {http_connect}\ ncontent_type:% {content_type}\ ntime_dns:% {time_namelookup}\ ntime_redirect:% {time_redirect}\ ntime_pretransfer:% {time_pretransfer}\ ntime_connect:% {time_starttransfer}\ ntime_total:% {time_total}:\ nspeed_download:% {speed _ download}\ n "" http://p_w_picpaths.apple.com/v/iphone-7/d/p_w_picpaths/overview/design_hero_large.jpg";

Http_code: 200

Http_connect:000

Content_type:p_w_picpath/jpeg

Time_dns:0.449

Time_redirect:0.000

Time_pretransfer:0.456

Time_connect:0.456

Time_starttransfer:0.465

Time_total:0.493:

Speed_download:419293.000

Weibo short domain name link

Curl-o / dev/null-s-w "http_code:% {http_code}\ nhttp_connect:% {http_connect}\ ncontent_type:% {content_type}\ ntime_dns:% {time_namelookup}\ ntime_redirect:% {time_redirect}\ ntime_pretransfer:% {time_pretransfer}\ ntime_connect:% {time_starttransfer}\ ntime_total:% {time_total}:\ nspeed_download:% {speed _ download}\ n "- L" http://t.cn/Rip1YJA"

Http_code: 200

Http_connect:000

Content_type:text/html;charset=GBK

Time_dns:0.210

Time_redirect:0.079

Time_pretransfer:0.240

Time_connect:0.240

Time_starttransfer:0.290

Time_total:0.369:

Speed_download:4349.000

4. Other

At present, you can only use curl to get the static page of the specified request, but it is still impossible to request all the links in the page to the

This does not really reflect the time it takes to access the page in the browser.

But when users report that it is slow to access a page

Access to the corresponding address through curl can basically be determined

Where is the main time-consuming of a single request?

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report