如何使用cURL一次测量请求和响应时间?
本文翻译自:How do I measure request and response times at once using cURL?
I have a web service that receives data in JSON format, processes the data, and then returns the result to the requester. 我有一个Web服务,它接收JSON格式的数据,处理数据,然后将结果返回给请求者。
I want to measure the request, response, and total time using cURL
. 我想使用cURL
测量请求,响应和总时间。
My example request looks like: 我的示例请求如下:
curl -X POST -d @file server:port
and I currently measure this using the time
command in Linux: 我目前使用Linux中的time
命令测量它:
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
? 有没有办法使用cURL
来衡量请求和响应时间?
#1楼
参考:https://stackoom.com/question/1EQeb/如何使用cURL一次测量请求和响应时间
#2楼
Here is the answer: 这是答案:
curl -X POST -d @file server:port -w %{time_connect}:%{time_starttransfer}:%{time_total}
All of the variables used with -w
can be found in man curl
. 与-w
一起使用的所有变量都可以在man curl
找到。
#3楼
From this brilliant blog post... https://blog.josephscott.org/2011/10/14/timing-details-with-curl/ 从这篇精彩的博客文章... https://blog.josephscott.org/2011/10/14/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>
). cURL支持格式化输出以获取请求的详细信息( 有关详细信息 ,请参阅cURL联机帮助页 ,在-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: 创建一个新文件curl-format.txt并粘贴到:
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... 或者在Windows上,它是......
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 -w "@curl-format.txt"
告诉cURL使用我们的格式文件
-o /dev/null
redirects the output of the request to /dev/null -o /dev/null
将请求的输出重定向到/ dev / null
-s
tells cURL not to show a progress meter -s
告诉cURL不要显示进度表
"http://wordpress.com/"
is the URL we are requesting. "http://wordpress.com/"
是我们要求的网址。 Use quotes particularly if your URL has "&" query string parameters 如果您的URL具有“&”查询字符串参数,请使用引号
And here is what you get back: 这是你得到的回报:
time_namelookup: 0.001time_connect: 0.037time_appconnect: 0.000time_pretransfer: 0.037time_redirect: 0.000
time_starttransfer: 0.092----------time_total: 0.164
Make a Windows shortcut (aka BAT file) 创建Windows快捷方式(也称为BAT文件)
Put this command in CURLTIME.BAT (in the same folder as curl.exe) 将此命令放在CURLTIME.BAT中(与curl.exe位于同一文件夹中)
curl -w "@%~dp0curl-format.txt" -o NUL -s %*
Then you can simply call... 然后你可以简单地打电话......
curltime wordpress.org
#4楼
Option 1. To measure total time
: 选项1.测量total time
:
curl -o /dev/null -s -w 'Total: %{time_total}s\n' https://www.google.com
Sample output: 样本输出:
Option 2. To get time to establish connection
, TTFB: time to first byte
and total time
: 选项2.为了有time to establish connection
, TTFB: time to first byte
total time
和total time
:
curl -o /dev/null -s -w 'Establish Connection: %{time_connect}s\nTTFB: %{time_starttransfer}s\nTotal: %{time_total}s\n' https://www.google.com
Sample output: 样本输出:
Ref: Get response time with curl 参考: 获得卷曲的响应时间
#5楼
A shortcut you can add to your .bashrc etc, based on other answers here: 您可以根据此处的其他答案添加到.bashrc等的快捷方式:
function perf {curl -o /dev/null -s -w "%{time_connect} + %{time_starttransfer} = %{time_total}\n" "$1"
}
Usage: 用法:
> perf stackoverflow.com
0.521 + 0.686 = 1.290
#6楼
I made a friendly formatter for sniffing curl requests to help with debugging ( see comments for usage ). 我做了一个友好的格式化程序来嗅探curl请求以帮助调试(参见使用注释)。 It contains's every known output parameter you can write out in an easy to read format. 它包含您可以用易于阅读的格式写出的每个已知输出参数。
https://gist.github.com/manifestinteractive/ce8dec10dcb4725b8513 https://gist.github.com/manifestinteractive/ce8dec10dcb4725b8513
如何使用cURL一次测量请求和响应时间?相关推荐
- php多线程模拟请求,浅谈php使用curl模拟多线程发送请求
每个PHP文件的执行是单线程的,但是php本身也可以用一些别的技术实现多线程并发比如用php-fpm进程,这里用curl模拟多线程发送请求.php的curl多线程是通过不断调用curl_multi_e ...
- 用php批处理图片,PHP中使用CURL发送get/post请求上传图片批处理功能
cURL是利用url语法规定传输文件和数据的工具.php中有curl拓展,一般用来实现网络抓取,模拟发送get post请求,文件上传. 在php中建立curl的基本步骤如下: 1.初始化 2. ...
- php curl post上传图片,PHP中使用CURL发送get/post请求上传图片批处理功能
cURL是利用url语法规定传输文件和数据的工具.php中有curl拓展,一般用来实现网络抓取,模拟发送get post请求,文件上传. 在php中建立curl的基本步骤如下: 1.初始化 2. ...
- Linux下在shell中使用curl模拟get,post请求访问接口并设置代理
在服用端做测试或查找问题的时候,难免要测试接口,测试接口最简单的方法就是利用shell的curl命令来模板get,post请求,每次都用,但是有些参数时间一长就记不清楚了,所以记录一下以备忘 curl ...
- curl 模拟 GET\POST 请求,以及 curl post 上传文件
curl 模拟 GET\POST 请求,以及 curl post 上传文件 一般情况下,我们调试数据接口,都会使用一个 postman 的工具,但是这个工具还是有点大了.事实上,我们在调试一些小功能的 ...
- php 响应时间,PHP下解决ajax请求服务器响应时间过长问题
PHP下解决ajax请求服务器响应时间过长的办法:首先在浏览器输入测试网址,找到Networky以及ajax发送的请求:然后找到TTFB的响应时间对应的php文件,并删掉这些代码:最后将数据库loca ...
- curl 模拟 GET\POST 请求
2019独角兽企业重金招聘Python工程师标准>>> curl post 案例如下: 1. 命令格式:curl http://ip:port/product/productDeta ...
- PHP cURL可以在单个请求中检索响应标头和正文吗?
本文翻译自:Can PHP cURL retrieve response headers AND body in a single request? Is there any way to get b ...
- php curl的数据后台如何接收,PHP curl以模拟put请求,后台无法接受到数据是怎么回事?...
我自己封装了curl工具类,测试表现:get,post,delete方式后台都能正确接收到前面传的参数,但是put方式就是获取不到参数. 1.相关代码: index.php 入口请求文件 requir ...
最新文章
- 将二叉查找树转化为链表的代码实现
- linux class device
- python现在好找工作吗-推崇Python这么多人,为什么他们找不到工作!
- 东尼•博赞的思维导图丛书之一 《大脑使用说明书》
- OpenGL 变换Transformations
- BZOJ #2874. 训练士兵(差分+离散化+主席树)
- cxf javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)
- [转载]心灵丨愿你早一点发现,你才是自己最重要的粉丝
- bootstrap $(“#xxx“).bootstrapTable(‘getData‘)值不对
- 微软云加速器助edoc2入云腾飞
- 【渝粤教育】电大中专跨境电子商务理论与实务_1作业 题库
- 计算机程序员求职信英语作文,电脑程序员英文求职信
- 为什么很多人打游戏感觉很快乐,然而学习工作中的满足感却很低
- 我是怎么学英语的(四级没过如何突破听说读写)
- win10下使用Winsat对系统进行评分
- 在类方法中可 用this来调用本类的类方法
- Android 快速为背景添加方格线
- PlatoFarm推出正式版游戏经济模型的特点分析
- 面试总结三 --- 浏览器与网络
- 关于网友0x1abin的MultiTimer