測試主機的回應時間很多時都會用到, 而 cURL 可以自訂輸出的格式, 以取得主機的回應時間。
首先建立儲存 cURL 格式的樣案:
$ vi curl-format.txt
加入以下內容:
1 2 3 4 5 6 7 8 |
time_namelookup: %{time_namelookup}\n time_connect: %{time_connect}\n time_appconnect: %{time_appconnect}\n time_pretransfer: %{time_pretransfer}\n time_redirect: %{time_redirect}\n time_starttransfer: %{time_starttransfer}\n ----------\n time_total: %{time_total}\n |
然後執行以下指令測試主機的回應時間:
1 |
# curl -w "@curl-format.txt" -o /dev/null -s "https://www.google.com/" |
然後會輸出類似以下的結果:
1 2 3 4 5 6 7 8 |
time_namelookup: 0.028 time_connect: 0.030 time_appconnect: 0.110 time_pretransfer: 0.110 time_redirect: 0.000 time_starttransfer: 0.150 ---------- time_total: 0.150 |
上面的 cURL 指令會測試 https://www.google.com/ 的回應時間, 將網址換成要測試的網址即可。