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
https://forums.phpfreaks.com/topic/284250-curl-load_time/
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
https://forums.phpfreaks.com/topic/284250-curl-load_time/#findComment-1460007
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.