Jump to content

curl load_time


Kobi

Recommended Posts

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.com
download 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.

Link to comment
Share on other sites

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'];
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.