简体   繁体   English

perl如何找到http请求完成的时间

[英]perl how to find time for http request completion

I have a form to fill and on submit, it will return result. 我有一张表格要填写并提交,它将返回结果。 Now, i want to calculate the time taken to fulfill my request ie time when result got displayed-time i clicked submit. 现在,我想计算完成我的请求所花费的时间,即结果显示的时间-我单击提交的时间。

I have no idea, how to do so. 我不知道该怎么做。 Please feel free to use any module. 请随时使用任何模块。 I dont know which parameter to use to check that response page is displayed. 我不知道要使用哪个参数来检查是否显示响应页面。 I have used reading title of result page just to check that response is displayed correctly. 我已经使用阅读结果页面的标题来检查响应是否正确显示。

my code: 我的代码:

use WWW::Mechanize;
use LWP::UserAgent;
my $m = WWW::Mechanize->new();
$m->get( "http://en.wikipedia.org/wiki/Main_Page" );
$m->submit_form(
    form_number => 1,
    fields    => { search  => 'honey', },
    button    => 'go'  #my time1 should start at this moment
);
#my time 2 should be recorded as soon as result page is displayed, i dont know what to use to get this time
$tmp=$m->title;
print "$tmp\n";

您可以使用WWW :: Mechanize :: Timed

You can capture the time when you submit the request and also immediately after result got displayed in the script using time function. 您可以使用时间功能捕获提交请求时的时间,也可以捕获结果在脚本中显示结果后的时间。 Then difference of both can give you the required time taken for the request. 然后两者的差异可以为您提供请求所需的时间。

Otherwise you can also try WWW::Mechanize::Timed as Pathak suggested. 否则,您也可以尝试WWW :: Mechanize :: Timed,如Pathak建议的那样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM