?
Solved

Download time

Posted on 2004-08-15
3
Medium Priority
?
218 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
_GeG_ earned 1500 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

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
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.
Suggested Courses

741 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