Curl獲取相關數據
使用cur -w/--write-out l獲取相關數據
幾個比較關鍵的參數:
url_effective 最后獲取的URL。
http_code 上一次HTTP(S)或FTP(S)操作返回的響應碼。在7.18.2版加入的response_code顯示同樣的信息。
http_connect 在最后一次對cURL的CONNECT請求的響應(從代理)中發現的數值代碼。 (在7.12.4版加入)
time_total 全部操作耗費的時間,單位為秒。精確到毫秒。
time_namelookup 從開始到域名解析完成耗費的時間,單位為秒。
time_connect TCP連接遠程主機(或代理服務器)所耗時間,單位為秒。
time_appconnect SSL/SSH/等與遠程主機連接/握手完成花費的時間,單位為秒。(在7.19.0 版加入)
time_pretransfer 從開始到文件將要傳輸前花費的時間,單位為秒。包括指定的協議所有預傳輸命令和negotiations。
time_redirect 所有重定向步驟的時間,包域名解析、連接、預傳輸和最后事務開始前的傳輸,單位為秒。time_redirect顯示多重重定向的完整執行時間。(在7.12.3版加入 )
time_starttransfer 從開始到第一個字節將被傳輸前耗費的時間,單位為秒。
這包括time_pretransfer和服務器需要的運算結果的時間。
size_download下載的總字節數。
size_upload上傳的總字節數。
size_header 下載的header的總字節數。
size_request 發送的HTTP請求的總字節數。
speed_download curl成功下載的平均下載速度。
speed_upload curl成功上傳的平均上傳速度。
3.獲取請求的耗時信息
針對特定的請求,通過curl可以獲取到各個環節的耗時情況,
比如域名解析的耗時,建立連接的耗時,服務端處理的耗時,總的耗時。
國內某合作方素材
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_connect}\ntime_starttransfer:%{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:image/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
蘋果官網圖片素材
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_connect}\ntime_starttransfer:%{time_starttransfer}\ntime_total:%{time_total}:\nspeed_download:%{speed_download}\n " "http://images.apple.com/v/iphone-7/d/images/overview/design_hero_large.jpg";
http_code: 200
http_connect:000
content_type:image/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
微博短域名鏈接
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_connect}\ntime_starttransfer:%{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.其他
目前只能用curl獲取到指定請求的靜態頁面,還是無法像瀏覽器那樣將頁面中的鏈接都請求到,
這樣就無法真實反應瀏覽器中訪問頁面的耗時情況。
不過當用戶反映訪問某個頁面慢的時候,
通過curl訪問對應的地址基本上可以確定,
單個請求主要耗時在哪里