Solved

Download time

Posted on 2004-08-15
3
186 Views
Last Modified: 2012-05-05
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
Comment
Question by:Aetia
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
_GeG_ earned 500 total points
ID: 11804255
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
 
LVL 25

Expert Comment

by:Marcus Bointon
ID: 11808197
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
 
LVL 9

Expert Comment

by:_GeG_
ID: 11865205
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

919 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

17 Experts available now in Live!

Get 1:1 Help Now