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

Download time

This is my second post to about calculating download time...

I got acceptable reply from this post:
http://www.experts-exchange.com/Web/Web_Languages/PHP/Q_21091358.html

I used this script In my PHP it seems to function.

However the result of the calculation of the downloading time is theoretical and it represents a minimal time (it takes the speed of connection and it doesn't know the speed of the distant server and the different roads that data can follow).

So if anyone knows how to upgrade it, let me know...
0
Aetia
Asked:
Aetia
  • 2
1 Solution
 
_GeG_Commented:
Hmm, since the other solution is too theoretical for you, here is the contrary :D
Choose the largest picture you have on your download html/php page. Let's say it is the picture of the software box (box.jpg)
now in html/php do this:
<?php session_start(); ?>
... html ...
<img src="<?php echo "box.php".SID; ?>" title="software box">
....html...

What was that? It just displays an image for your site, but because it is delivered by a php script, the time for the transfer can be measured.

in box.php
<?php
$image_name='box.jpg');
session_start();
list($a, $b)=split(' ', microtime());
$start= $a+$b;
header("Content-Type: image/jpeg");
if (!isset($_SESSION['speed_in_bytes_per_second'])){
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
}
readfile($image_name);
list($a, $b)=split(' ', microtime());
$download_time=($a+$b-$start);
$_SESSION['speed_in_bytes_per_second']=filesize($image_name)/$download_time;
?>

What was that? This file just sends the image and measures the time it takes. Then the download speed is saved in a session. The headers are a against caching, so our download rate is not messed up.

ok, and here the actual download.php
<?php
session_start();
if ($_SESSION['speed_in_bytes_per_second'] > 20000){ // if download is faster than 20k/s
   //use large file
} else {
   //use small file
}

Be careful, the image that you use for testing must be large enough to give a good estimation of the download speed.
0
 
Marcus BointonCommented:
I don't think that will work well - setting non-caching headers will prevent it from being cached across multiple requests, but it won't affect a single request which may have inline transparent proxy caching, as most large ISPs do, so it may download very fast to the ISP's proxy, then (slowly) on to the requester, giving you an invalid result. In order to do this accurately, you need to measure it at the client end, which essentially means using JavaScript.

Not sure if this might be helpful as it's for uploads, but it's interesting technique anyway:

http://www.raditha.com/php/progress.php
0
 
_GeG_Commented:
My solution will probably give a rate which is too low. That is because the vrowser open more than one connection at once when downloding images. So probably you will have to use a little javascript to load the image after the complete page has loaded, something like:

<body onload="testIt()">
..
<script>
function testIt(){
  i=new Image();
  i.location="<?php echo "box.php".SID; ?>";
}
</script>
0

Featured Post

Independent Software Vendors: 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
Tackle projects and never again get stuck behind a technical roadblock.
Join Now