iis服务器助手广告广告
返回顶部
首页 > 资讯 > 服务器 >获取站点的各类响应时间(dns解析时间,响应时间,传输时间)
  • 512
分享到

获取站点的各类响应时间(dns解析时间,响应时间,传输时间)

响应时间时间站点 2022-06-04 21:06:05 512人浏览 泡泡鱼
摘要

有时候为了测试网络情况,需要返回每个阶段的耗时时间,比如DNS解析耗时,建立连接所消耗的时间,从建立连接到准备传输所使用的时间,从建立连接到传输开始所使用的时间,整个过程耗时,下载的数据量,下载速度,上传数

有时候为了测试网络情况,需要返回每个阶段的耗时时间,比如DNS解析耗时,建立连接所消耗的时间,从建立连接到准备传输所使用的时间,从建立连接到传输开始所使用的时间,整个过程耗时,下载的数据量,下载速度,上传数据量,上传速度等等。下面的脚本获取以上信息:

CURL的资料参见: Http://curl.haxx.se/libcurl/c/curl_easy_getinfo.html


###################################
### author: www.ttlsa.com ###
### QQ群: 39514058 ###
### E-mail: service@ttlsa.com ###
###################################
use strict;
use Data::Dumper;
use WWW::Curl::Easy;

if(!@ARGV){
print "Usaging: $0 urln";
print "For example: $0 www.ttlsa.comn";
exit;
}

my $curl = new WWW::Curl::Easy;
open my $response_body,">/dev/null";
$curl->setopt(CURLOPT_HEADER,1);
$curl->setopt(CURLOPT_URL, $ARGV[0]);
$curl->setopt(CURLOPT_WRITEDATA,$response_body);
$curl->perfORM;
my $err = $curl->errbuf;
if(!$err){
my $st = &getTime;
my $http_code = $curl->getinfo(CURLINFO_RESPONSE_CODE);
my $http_dns_time = $curl->getinfo(CURLINFO_NAMELOOKUP_TIME);
my $http_conn_time = $curl->getinfo(CURLINFO_CONNECT_TIME);
#my $http_APP_time = $curl->getinfo(CURLINFO_APPCONNECT_TIME);
my $http_PRE_TRAN_time = $curl->getinfo(CURLINFO_PRETRANSFER_TIME);
my $http_START_TRAN_time = $curl->getinfo(CURLINFO_STARTTRANSFER_TIME);
my $http_TOTAL_time = $curl->getinfo(CURLINFO_TOTAL_TIME);
my $http_SIZE_DOWN = $curl->getinfo(CURLINFO_SIZE_DOWNLOAD);
my $http_SPEED_DOWN = $curl->getinfo(CURLINFO_SPEED_DOWNLOAD);

printf "local_time: %s, http_code: %d, dns_time: %.3fms, conn_time: %.3fms, pre_tran_time: %.3fms, start_tran_time: %.3fms, total_time: %.3fms, size_download: %dB, speed_download: %dB/s",($st,$http_code,$http_dns_time,$http_conn_time,$http_PRE_TRAN_time,$http_START_TRAN_time,$http_TOTAL_time,$http_SIZE_DOWN,$http_SPEED_DOWN);
write;

format STDOUT_TOP=
站点各类响应时间明细-@||
$%
=========================
+---------------------+------+-------------+--------------+--------------------------+------------------------+-------------+-----------+------------+
| 本地时间 | 状态 | DNS解析时间 | 建立连接时间 | 从建立连接到准备传输时间 |从建立连接到开始传输时间| 整个过程时间| 下载数据量|平均下载速度|
+---------------------+------+-------------+--------------+--------------------------+------------------------+-------------+-----------+------------+
.

format STDOUT=
|@<<<<<<<<<<<<<<<<<<<<| @<<<<| @<<<<<<<<<<<| @<<<<<<<<<<<<| @<<<<<<<<<<<<<<<<<<<<<<<<| @<<<<<<<<<<<<<<<<<<<<<<| @<<<<<<<<<<<| @<<<<<<<<<| @<<<<<<<<<<|
$st,$http_code,$http_dns_time."ms",$http_conn_time."ms",$http_PRE_TRAN_time."ms",$http_START_TRAN_time."ms",$http_TOTAL_time."ms",$http_SIZE_DOWN."B",$http_SPEED_DOWN."B/s"
+---------------------+------+-------------+--------------+--------------------------+------------------------+--------------+----------+------------+
.
}else{
print "Error: $errn";
}

sub getTime()
{
my @time=(localtime)[5,4,3,2,1,0];
$time[0]+=1900;
$time[1]+=1;
return sprintf("%04u-%02u-%02u %02u:%02u:%02u",@time);
}



查看图片

shell命令下也有相同的命令如下所示:


# curl -o /dev/null -s -w %{http_code}:%{http_connect}:%{time_namelookup}:%{time_connect}:%{time_pretransfer}:%{time_starttransfer}:%{time_total}:%{size_download}:%{speed_download} www.ttlsa.com


不解释了,具体参见 man curl

使用 cURL 获取站点的各类响应时间 ? dns解析时间,响应时间,传输时间


curl -o /dev/null -s -w %{http_code}:%{http_connect}:%{content_type}:%{time_namelookup}:%{time_redirect}:%{time_pretransfer}:%{time_connect}:%{time_starttransfer}:%{time_total}:%{speed_download} digdeeply.org


这是一个本人博客站点执行 curl 命令的情况。输出通常是 HTML 代码,通过 -o 参数发送到 /dev/null。-s 参数去掉所有状态信息。-w 参数让 curl 输出的计时器的状态信息。

查看图片

一次http请求中的各个时间段-dns解析,等待服务器响应,获取内容等

下边对-w参数做个详细的解释,由我(DigDeeply)翻译。有不对的地方请大家指出。(英文原文:http://curl.haxx.se/docs/manpage.html)
以下是可用的变量名:

 -w, --write-out
 以下变量会按CURL认为合适的格式输出,输出变量需要按照%{variable_name}的格式,如果需要输出%,double一下即可,即%%,同时,n是换行,r是回车,t是TAB。

url_effective The URL that was fetched last. This is most meaningful if you've told curl to follow location: headers.

filename_effective The ultimate filename that curl writes out to. This is only meaningful if curl is told to write to a file with the --remote-name or --output option. It's most useful in combination with the --remote-header-name option. (Added in 7.25.1)

http_code http状态码,如200成功,301转向,404未找到,500服务器错误等。(The numerical response code that was found in the last retrieved HTTP(S) or FTP(s) transfer. In 7.18.2 the alias response_code was added to show the same info.)

http_connect The numerical code that was found in the last response (from a proxy) to a curl CONNECT request. (Added in 7.12.4)

time_total 总时间,按秒计。精确到小数点后三位。 (The total time, in seconds, that the full operation lasted. The time will be displayed with millisecond resolution.)

time_namelookup DNS解析时间,从请求开始到DNS解析完毕所用时间。(The time, in seconds, it took from the start until the name resolving was completed.)

time_connect 连接时间,从开始到建立tcp连接完成所用时间,包括前边DNS解析时间,如果需要单纯的得到连接时间,用这个time_connect时间减去前边time_namelookup时间。以下同理,不再赘述。(The time, in seconds, it took from the start until the TCP connect to the remote host (or proxy) was completed.)

time_appconnect 连接建立完成时间,如SSL/ssh等建立连接或者完成三次握手时间。(The time, in seconds, it took from the start until the SSL/SSH/etc connect/handshake to the remote host was completed. (Added in 7.19.0))

time_pretransfer 从开始到准备传输的时间。(The time, in seconds, it took from the start until the file transfer was just about to begin. This includes all pre-transfer commands and neGotiations that are specific to the particular protocol(s) involved.)

time_redirect 重定向时间,包括到最后一次传输前的几次重定向的DNS解析,连接,预传输,传输时间。(The time, in seconds, it took for all redirection steps include name lookup, connect, pretransfer and transfer before the final transaction was started. time_redirect shows the complete execution time for multiple redirections. (Added in 7.12.3))

time_starttransfer 开始传输时间。在发出请求之后,WEB 服务器返回数据的第一个字节所用的时间(The time, in seconds, it took from the start until the first byte was just about to be transferred. This includes time_pretransfer and also the time the server needed to calculate the result.)

size_download 下载大小。(The total amount of bytes that were downloaded.)

size_upload 上传大小。(The total amount of bytes that were uploaded.)

size_header 下载的header的大小(The total amount of bytes of the downloaded headers.)

size_request 请求的大小。(The total amount of bytes that were sent in the HTTP request.)

speed_download 下载速度,单位-字节每秒。(The average download speed that curl measured for the complete download. Bytes per second.)

speed_upload 上传速度,单位-字节每秒。(The average upload speed that curl measured for the complete upload. Bytes per second.)

content_type 就是content-Type,不用多说了,这是一个访问我博客首页返回的结果示例(text/html; charset=UTF-8);(The Content-Type of the requested document, if there was any.)

num_connects Number of new connects made in the recent transfer. (Added in 7.12.3)

num_redirects Number of redirects that were followed in the request. (Added in 7.12.3)

redirect_url When a HTTP request was made without -L to follow redirects, this variable will show the actual URL a redirect would take you to. (Added in 7.18.2)

ftp_entry_path The initial path libcurl ended up in when logging on to the remote FTP server. (Added in 7.15.4)

ssl_verify_result ssl认证结果,返回0表示认证成功。( The result of the SSL peer certificate verification that was requested. 0 means the verification was successful. (Added in 7.19.0))

若多次使用-w参数,按最后一个的格式输出。If this option is used several times, the last one will be used.

--结束END--

本文标题: 获取站点的各类响应时间(dns解析时间,响应时间,传输时间)

本文链接: https://www.lsjlt.com/news/17852.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • 如何获取站点的各类响应时间
    这篇文章主要讲解了“如何获取站点的各类响应时间”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“如何获取站点的各类响应时间”吧!有时候为了测试网络情况,需要返回每个阶段的耗时时间,比如DNS解析...
    99+
    2023-06-09
  • 缩短Vista响应时间
    微软操作系统的用户应该都遭受过“程序正在响应”的痛苦,那种迟迟没有反应的系统状态真是让忍受不了。针对这种情况,有的网友会手动对系统进行优化,或者借助第三方优化类的软件进行优化,以避免程序响应时间过...
    99+
    2023-05-23
    时间 响应 Vista
  • Win7程序未响应时间过长如何缩短程序的响应时间
      Windows用户常常会遇到“程序未响应”这样的系统提示,要么手动强行终止,要么继续等待期响应,不过大多数程序出现此问题时,很难再活过来了。这个问题在win7中也是常常遇到,要怎么样才能缩短程...
    99+
    2023-06-02
    Win7 程序响应时间 时间 过长 程序 响应
  • LoadRunner中90%响应时间的理解
    最近有朋友老问关于90%的响应时间不太理解,顾摘录如下内容供大家参考:官方解释:Solution: The 90th percentile is the value for which 90% of the data points are ...
    99+
    2023-06-05
  • python脚本测试网站响应时间
    可以使用Firefox的Firebug插件查看网站的响应时间,今天我们用python实现这个功能。#!/usr/bin/env python#coding=utf8#Author zhaodongimport os,sys  import ...
    99+
    2023-01-31
    脚本 响应时间 测试
  • Vue如何获取两个时间点之间的所有间隔时间
    目录获取两个时间点之间的所有间隔时间获取两个时间之间的 间隔时间获取两个日期之间的间隔日期获取指定两个月份之间的 间隔月份获取两个时间点之间的所有间隔时间 说明 使用的是vue@2....
    99+
    2024-04-02
  • php如何修改响应时间
    本文将为大家详细介绍“php如何修改响应时间”,内容步骤清晰详细,细节处理妥当,而小编每天都会更新不同的知识点,希望这篇“php如何修改响应时间”能够给你意想不到的收获,请大家跟着小编的思路慢慢深入,具体内容如下,一起去收获新知识吧。php...
    99+
    2023-06-06
  • 怎么理解Oracle响应时间分析报告
    本篇内容主要讲解“怎么理解Oracle响应时间分析报告”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“怎么理解Oracle响应时间分析报告”吧!Oracle响应时...
    99+
    2024-04-02
  • PHP获取时间戳、获取天周月的起始时间、指定时间所在周、指定时间的各个周等相关函数
    目录 一、时间戳和日期互相转换 二、PHP获取今日、昨日、上周、本周、上月、本月的起始时间戳 三、获取当前周的每天的起始时间 四、获取周的起始时间 1、根据指定时间获取所在周的起始时间和结束时间 2、通过时间戳 获取某周的开始时间和结束时间...
    99+
    2023-09-01
    php
  • js如何以天为单位获取响应的时间戳
    小编给大家分享一下js如何以天为单位获取响应的时间戳,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!以“天”为单位获取响应的时间戳通常都会获取三天前的时间,12 个...
    99+
    2023-06-27
  • Go获取两个时间点时间差的具体实现
    目录获取当前时间及其秒、毫秒、纳秒数获取两个时间点时间差代码获取指定时间前的时间 获取指定时间后的时间获取当前时间及其秒、毫秒、纳秒数 now := time.Now() ...
    99+
    2024-04-02
  • win7程序响应时间长怎么解决
    今天小编给大家分享一下win7程序响应时间长怎么解决的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。解决方法:使用快捷键win...
    99+
    2023-06-28
  • nginx设置服务器响应时间长短
    方法一.宝塔部署nginx设置服务器响应时间长短 设置完重启nginx即可 方法二. config配置 http { # ... # 设置连接超时时间为30秒 fastcgi_connect_timeout 30...
    99+
    2023-08-19
    服务器 nginx java
  • PHP编程中如何优化响应时间?
    在现代Web应用程序中,快速响应时间是至关重要的。用户不喜欢等待网页加载和处理请求的时间过长。在PHP编程中,优化响应时间是一个重要的问题。在本文中,我们将介绍一些优化PHP响应时间的技巧。 使用缓存 缓存是提高响应时间的最有效方法之...
    99+
    2023-07-01
    编程算法 响应 索引
  • ASP 打包是否影响响应时间?如何优化?
    在 ASP 中,打包是将多个文件组合成一个文件,以减少网络传输的数量和大小。打包可以显著减少页面的加载时间和带宽使用。然而,打包也可能会影响响应时间,特别是在处理大量的请求时。在本文中,我们将探讨 ASP 打包的优缺点,并介绍如何优化 A...
    99+
    2023-10-15
    打包 响应 日志
  • ASP 接口响应学习笔记:如何优化响应时间?
    随着互联网的快速发展,越来越多的企业和个人开始关注网站和应用程序的性能和响应速度。作为一个 ASP 开发者,你可能已经意识到了优化响应时间的重要性。在本文中,我们将分享一些优化 ASP 接口响应时间的技巧和最佳实践。 最小化 HTTP ...
    99+
    2023-06-22
    学习笔记 接口 响应
  • 如何调整 Linux 上 PHP API 的响应时间?
    Linux 上 PHP API 的响应时间是一个非常重要的指标,它直接影响着用户的体验和网站的可用性。在本文中,我们将介绍如何调整 Linux 上 PHP API 的响应时间,以提高网站的性能和用户体验。 一、优化 PHP 代码 首先,我们...
    99+
    2023-11-08
    api 响应 linux
  • MySQL获取当前时间的各种方式
    1 获取当前完整时间 1.1 now()函数 select now(); 输出: 2023-02-15 10:46:17 1.2 sysdate()函数 select sysdate(); 输出: 2023-02-15 10...
    99+
    2023-08-31
    mysql 数据库 Powered by 金山文档
  • PHP-FPM性能优化:加速你的网站响应时间
    引言:随着互联网的快速发展,网站的性能成为了用户体验和搜索引擎排名的重要因素之一。而作为网站开发的常用语言,PHP的性能优化显得尤为重要。本文将重点介绍PHP-FPM性能优化的相关内容,并给出具体的代码示例,帮助你加速网站的响应时间。一、使...
    99+
    2023-10-21
    - 性能优化 - PHP-FPM - 响应时间加速
  • java的LocalDateTime类来获取当天时间、前一天时间,本周的开始和结束时间、本月的开始和结束时间
     直接上代码: // 获取当天日期 LocalDate now = LocalDate.now(); // 当天开始时间 LocalDateTime todayStart = n...
    99+
    2023-10-12
    java 开发语言
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作