如何使用cURL一次测量请求和响应时间? [英] How do I measure request and response times at once using cURL?
问题描述
我有一个网络服务接收JSON格式的数据,处理数据,然后将结果返回给请求者。
我想测量请求,响应和总时间使用 cURL
。
我的示例请求如下:
curl -X POST -d @file server:port
并且我目前使用Linux中的时间
命令来衡量这一点:
code> time curl -X POST -d @file server:port
有任何方法来测量请求和响应时间。 cURL
?
。 https://josephscott.org/archives/2011/10/timing -details-with-curl /
cURL支持请求的格式化输出(请参阅 curl联机帮助页, -w,-write-out< format>
)。
-
创建新文件,卷曲-format.txt并粘贴:
time_namelookup:%{time_namelookup} \\\
time_connect:%{time_connect} \\\
time_appconnect:%{time_appconnect} \\\
time_pretransfer:%{time_pretransfer} \\\
time_redirect:%{time_redirect} \\\
time_starttransfer:%{time_starttransfer} \\\
---------- \\\
time_total:%{time_total} \\\
$ c $
<$ p $ p>curl -w@ curl-format.txt-o / dev / null -shttp://wordpress.com/
pre>
或在Windows上,它是...
w@ curl-format.txt-o NUL -shttp://wordpress.com/
此操作:
-w@ curl-format.txt
告诉cURL使用我们的格式文件
-o / dev / null
将请求的输出重定向到/ dev / null
-s
告诉cURL不显示进度表
http://wordpress.com/
是
我们要求的网址。如果您的网址有&,请使用引号查询字符串参数
这里是你回来的:
time_namelookup:0.001
time_connect:0.037
time_appconnect:0.000
time_pretransfer:0.037
time_redirect:0.000
time_starttransfer:0.092
----------
time_total:0.164
创建Windows快捷方式(也称为BAT文件)
命令在CURLTIME.BAT(在与curl.exe相同的文件夹中)
curl -w@%〜dp0curl格式。 txt-o NUL -s%*
然后你可以简单地调用...
curltime wordpress.org
I have a web service that receives data in JSON format, processes the data, and then returns the result to the requester.
I want to measure the request, response, and total time using cURL
.
My example request looks like:
curl -X POST -d @file server:port
and I currently measure this using the time
command in Linux:
time curl -X POST -d @file server:port
The time command only measures total time, though - which isn't quite what I am looking for.
Is there any way to measure request and response times using cURL
?
From this brilliant blog post... https://josephscott.org/archives/2011/10/timing-details-with-curl/
cURL supports formatted output for the details of the request (see the cURL manpage for details, under -w, –write-out <format>
). For our purposes we’ll focus just on the timing details that are provided.
Create a new file, curl-format.txt, and paste in:
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
Make a request:
curl -w "@curl-format.txt" -o /dev/null -s "http://wordpress.com/"
Or on Windows, it's...
curl -w "@curl-format.txt" -o NUL -s "http://wordpress.com/"
What this does:
-w "@curl-format.txt"
tells cURL to use our format file
-o /dev/null
redirects the output of the request to /dev/null
-s
tells cURL not to show a progress meter
"http://wordpress.com/"
is
the URL we are requesting. Use quotes particularly if your URL has "&" query string parameters
And here is what you get back:
time_namelookup: 0.001
time_connect: 0.037
time_appconnect: 0.000
time_pretransfer: 0.037
time_redirect: 0.000
time_starttransfer: 0.092
----------
time_total: 0.164
Make a Windows shortcut (aka BAT file)
Put this command in CURLTIME.BAT (in the same folder as curl.exe)
curl -w "@%~dp0curl-format.txt" -o NUL -s %*
Then you can simply call...
curltime wordpress.org
这篇关于如何使用cURL一次测量请求和响应时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!