measuring response times

Posted on 2008-11-14
Last Modified: 2013-12-06

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?

Question by:Vlearns
    LVL 12

    Expert Comment

    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.
    LVL 82

    Accepted Solution


     * 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, "");
    curl_setopt($ch, CURLOPT_HEADER, 0);
    //record time right before sending request
    $time_start = microtime_float();
    //send request
    //record time right after request
    $time_end = microtime_float();
    $time = $time_end - $time_start;
    echo "request took $time seconds\n";

    Open in new window


    Author Comment

    are the time units correct, is it really seconds?
    LVL 12

    Expert Comment

    Yes. The results are in seconds. I take it they are longer than you expected?
    LVL 82

    Expert Comment

    >>are the time units correct, is it really seconds?
    In case you need "confirmation", "Yes", the units are seconds.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now