Solved

Download time

Posted on 2004-08-15
3
207 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 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to implement server side field validation and display customized error messages to the client.
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

726 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