Solved

Download time

Posted on 2004-08-15
3
175 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
Comment Utility
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:Squinky
Comment Utility
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_
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
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.

744 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

16 Experts available now in Live!

Get 1:1 Help Now