• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 463
  • Last Modified:

measuring response times

Hi

I am running php on free bsd . I am using curl to make a call to webservice. I want to measure the time it took to get back the response

how do i do it?

0
Vlearns
Asked:
Vlearns
  • 2
  • 2
1 Solution
 
Hugh FraserConsultantCommented:
If you're using the php cURL bindings, you can use the microtime function to get a very accurate timestamp before and after the web page is retrieved, and calculate the delta.

If you're looking for a way to monitor the response time on a regular basis, look at a tool like OpenNMS to track it.
0
 
hieloCommented:

<?php
/**
 * Simple function to replicate PHP 5 behaviour
 */
function microtime_float()
{
    list($usec, $sec) = explode(" ", microtime());
    return ((float)$usec + (float)$sec);
}
 
 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);
 
//record time right before sending request
$time_start = microtime_float();
 
//send request
curl_exec($ch);
 
//record time right after request
$time_end = microtime_float();
 
curl_close($ch);
$time = $time_end - $time_start;
 
echo "request took $time seconds\n";
?> 

Open in new window

0
 
VlearnsAuthor Commented:
are the time units correct, is it really seconds?
thanks!
0
 
Hugh FraserConsultantCommented:
Yes. The results are in seconds. I take it they are longer than you expected?
0
 
hieloCommented:
>>are the time units correct, is it really seconds?
In case you need "confirmation", "Yes", the units are seconds.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now