跳到主要内容

curl详细时间统计

· 阅读需 1 分钟

curl详细时间统计

curl_timing() {
if [[ -z "$1" ]]; then
echo "请提供URL。"
return 1
fi

if [[ -z "$2" ]]; then
echo "请提供请求次数。"
return 1
fi

if [[ -z "$3" ]]; then
echo "请提供每次请求间隔时间(秒)。"
return 1
fi

local url=$1
local count=$2
local wait=$3
local format=" time_namelookup: %{time_namelookup}s\n time_connect: %{time_connect}s\n time_appconnect: %{time_appconnect}s\n time_pretransfer: %{time_pretransfer}s\n time_redirect: %{time_redirect}s\n time_starttransfer: %{time_starttransfer}s\n ----------\n time_total: %{time_total}s\n"

for i in {1..$count}; do
echo "Request #$i:"
curl -w "$format" -o /dev/null -s "$url"
echo ""
sleep $wait
done
}
$ curl_timing https://xxxx.com 10 1

参考