Kobi Posted November 25, 2013 Share Posted November 25, 2013 Hi, I write this code to test the download time and size of a website, but is showing incorrct data. example: Took 0.586468 seconds to send a request to http://something.comdownload size 0 <?php include("../includes/layouts/header.php");?> <div id="getload"> <?php error_reporting(E_ALL | E_STRICT); // Initialize cURL with given url $url = $_POST['website_name']; $ch = curl_init($url); // Create a curl handle //$ch = curl_init('http://www.yahoo.com/'); // Execute curl_exec($ch); // Check if any error occurred if(!curl_errno($ch)) { $info = curl_getinfo($ch); echo 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url'] . '<br>download size ' . $info['size_download']; } // Close handle curl_close($ch); ?> </div> <?php include("../includes/layouts/footer.php");?> what is the currect way to display the download time and download size? Thanks. Quote Link to comment Share on other sites More sharing options...
.josh Posted November 25, 2013 Share Posted November 25, 2013 total_time is the total time for the complete transaction. There's more to the request involved than just downloading the physical contents. It includes time for name resolution, establishing connection, any redirect(s), general server processing, etc.. So even if 0 bytes of content were returned, total_time would still have a certain amount of overhead. pretransfer_time is the time passed since the start of the curl request to just before the file transfer begins. So a more accurate estimate of actual download time would be $downloadTime = $info['total_time'] - $info['pretransfer_time']; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.