測量單個或多個URL的第一字節。可以向您展示最快,最慢和中間的TTFB值以及選項記錄所有響應標頭。

Usage: ttfb [options] url [url...]
-d debug
-l <log file> (infers -d) log response headers. Defaults to ./curl.log
-n <number> of times to test time to first byte
-o <option> pass options to curl (e.g. -o "-k" will make curl ignore invalid certificates)
-v verbose output. Show response breakdown (DNS lookup, TLS handshake etc)
隱式使用Curl's -L選項遵循重定向鏈。
可以通過使用-d來記錄所有響應標頭(默認日誌文件為./curl.log )。
通過指定-l /some/file來覆蓋默認日誌文件。
通過指定調用URL的次數來獲得最快,最慢和中值TTFB值;使用-n2進行2個測試, -n5 for 5,依此類推。
使用計算%{time_starttransfer¹} - %{time_appconnect²}該計算不包括任何連接開銷,以更好地近似DevTool的TTFB圖。
st time_starttransfer
從開始的時間到幾秒鐘,直到第一個字節即將被轉移。這包括Time_pretransfer以及服務器計算結果所需的時間。
time_appconnect
從秒開始的時間從開始到SSL/SSH/ETC連接/握手到遠程主機。
基於https://github.com/sandeepraju的要點
由[email protected]修改,@jaygooby
從主分支下載腳本,並使其可執行:
curl -LJO https://raw.githubusercontent.com/jaygooby/ttfb.sh/master/ttfb
chmod +x ./ttfb
Usage: ttfb [options] url [url...]
-d debug
-l <log file> (infers -d) log response headers. Defaults to ./curl.log
-n <number> of times to test time to first byte
-o <option> pass options to curl (e.g. -o "-k" will make curl ignore invalid certificates)
-v verbose output. Show response breakdown (DNS lookup, TLS handshake etc)
基本用法:
$ ttfb example.com
.227436
帶有詳細響應分解的基本用法:
$ ttfb -v https://example.com
DNS lookup: 0.005152 TLS handshake: 0.000000 TTFB including connection: 0.200831 TTFB: .200831 Total time: 0.201132
多次測試:
$ ttfb -n 5 example.com/example/url
.....
fastest .177263 slowest .214302 median .179957
測試多個URL:
$ ttfb bbc.co.uk news.bbc.co.uk
bbc.co.uk .049985
news.bbc.co.uk .054122
多次測試多個URL:
$ ttfb -n 5 bbc.co.uk news.bbc.co.uk
.....
.....
bbc.co.uk fastest .030936 slowest .057755 median .034663
news.bbc.co.uk fastest .031413 slowest .182791 median .035001
指定多個測試時,詳細響應分解:
$ ttfb -v -n 5 bbc.co.uk
DNS lookup: 0.005335 TLS handshake: 0.102314 TTFB including connection: 0.148328 TTFB: .046014 Total time: 0.646115
DNS lookup: 0.005322 TLS handshake: 0.102609 TTFB including connection: 0.150693 TTFB: .048084 Total time: 0.644611
DNS lookup: 0.004277 TLS handshake: 0.102066 TTFB including connection: 0.172199 TTFB: .070133 Total time: 1.196256
DNS lookup: 0.004444 TLS handshake: 0.107375 TTFB including connection: 0.160771 TTFB: .053396 Total time: 0.637290
DNS lookup: 0.005352 TLS handshake: 0.118882 TTFB including connection: 0.168772 TTFB: .049890 Total time: 0.653761
fastest .046014 slowest .070133 median .049890
將所有響應標頭記錄到多個URL的所有響應標頭:
ttfb -d -n 2 bbc.co.uk https://www.bbc.co.uk/weather
..
..
bbc.co.uk fastest .027550 slowest .055215 median .041382
https://www.bbc.co.uk/weather fastest .101020 slowest .297923 median .199471
$ ls *.log
bbc_co_uk-curl.log https___www_bbc_co_uk_weather-curl.log
$ cat https___www_bbc_co_uk_weather-curl.log
HTTP/2 200
server: openresty
x-cache-action: MISS
vary: Accept-Encoding,X-BBC-Edge-Cache,X-BBC-Edge-Scheme,X-CDN
x-cache-age: 0
cache-control: private, stale-while-revalidate=10, max-age=0, must-revalidate
content-type: text/html;charset=utf-8
x-mrid: w1
date: Thu, 11 Apr 2019 17:08:07 GMT
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
x-lb-nocache: true
x-msig: 24e37f81323984e4e45b8048f9e3c94a
x-frame-options: SAMEORIGIN
content-length: 1077454
HTTP/2 200
server: openresty
x-cache-action: MISS
vary: Accept-Encoding,X-BBC-Edge-Cache,X-BBC-Edge-Scheme,X-CDN
x-cache-age: 0
cache-control: private, stale-while-revalidate=10, max-age=0, must-revalidate
content-type: text/html;charset=utf-8
x-mrid: w1
date: Thu, 11 Apr 2019 17:08:08 GMT
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
x-lb-nocache: true
x-msig: 24e37f81323984e4e45b8048f9e3c94a
x-frame-options: SAMEORIGIN
content-length: 1077454
請參閱https://blog.cloudflare.com/a-question-of-timing/- and https://curl.haxx.se/docs/manpage.html,以解釋捲曲變量與轉移的各個階段的關係。
為了更好地近似DevTool的TTFB,我們考慮沒有連接開銷的時間: %{time_starttransfer} - %{time_appconnect}
使用骯髒的eval進行TTFB算術。取決於bc和column命令。
如果您想提交PR,請確保所有現有的測試通過,並且添加了新功能,請在測試套件中添加測試。
要運行測試,請從項目根部make 。您需要在$PATH中安裝蝙蝠核。
如果您只想進行一兩次測試,請在您不在乎的測試中取消# skip線,因此他們閱讀了skip ,然後將跳過這些測試。
有關更多詳細信息,請參見CONTRIBUTING.md 。
設置多個請求( -n 2等)選項時顯示進度
-o選項) 當提供多個URL時,按最快的ttfb對輸出進行排序
顏色代碼根據響應的速度,標準響應中的TTFB:圖。