Solved

Download time

Posted on 2004-08-12
4
230 Views
Last Modified: 2008-03-06
UNGRENT, 500 points given...

Has enybody got script to show file download time. App should recognize somehow visitors connection speed itself.
0
Comment
Question by:Aetia
  • 2
  • 2
4 Comments
 
LVL 3

Expert Comment

by:thecode101
ID: 11784238
Try this:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language = "JavaScript">
// Remove down to "ConnectionSpeed Detection section" if you don't want to use cookies
// If you drop a cookie it can be picked up on return by php or something else
function setCookie(name, value, expire ){
document.cookie = name + "=" + escape(value) + ((expire==null ?
"":(";expires=" + expire.toGMTString())));
// alert('A cookie called '+name+' is now set with value: '+value); //enable to alert user of cookie
}
function getExpireDate(){
var expires = new Date();
expires.setTime((new Date().getTime() + 1000*60*60*24*365));
return expires;
}
// ConnectionSpeed Detection section
var datasize=31468; // Size of data being transferred, in Bytes
var startTime=0;
var endTime=0;
var date=0;
var ctype="";
var textMessage="";
function calcThroughput() {
var diffTimeMilliseconds = endTime - startTime;
var diffTimeSeconds = diffTimeMilliseconds/1000;
var bits = (datasize*8);    // convert Bytes to bits,
var kbits = bits/1024;    // convert bits to kbits
var throughput = kbits/(diffTimeSeconds*100/100);
throughput = throughput * .93; // account for IP packet header overhead - averages about 7%
setCookie("MediaThroughput", throughput, getExpireDate()); // Remove to not use cookie
if (throughput < 600){ctype="medium.html";}
if (throughput < 560){ctype="low.html";}
if (throughput > 600){ctype="high.html";}
textMessage = "Bandwidth: <B>" + ctype + "</B><br>time to load: (sec): <B>" + diffTimeSeconds + "</B><BR>kbits loaded:<B> " + kbits + "</B><BR>Throughput (kbps): <B>" + throughput +"</B>"
var sPath = window.location.pathname;
var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
document.location = sPath + "?speed=" + bits;
}
</script>
</head>

<body>
<?php
if (!$speed)
{
echo "<script language = \"Javascript\">
date = new Date();
endTime=date.getTime();
calcThroughput();
</script>";
}

$size = filesize ("path/to/filename");
$speed = floatval($speed);
$size = floatval($size);
$downloadTime = ceil($size / $speed);
echo $downloadTime;
?>

</body>
</html>

Code borrowed and modified from:
http://www.gidforums.com/t-1285.html
http://twebman.lunarpages.com/js/BandwidthRedirect.htm
0
 
LVL 3

Accepted Solution

by:
thecode101 earned 500 total points
ID: 11794476
The download time is returned in seconds. If you have any more questions or if this does not solve your question let me know.
0
 

Author Comment

by:Aetia
ID: 11795521
Thank you...

I havent tested it... But I will give you your points... :D
0
 

Author Comment

by:Aetia
ID: 11800966
I used your 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).
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

Suggested Solutions

Title # Comments Views Activity
Responsive Design Tools 6 38
php variable basic question 12 27
Filter wordpress query 3 9
Web Reply Form - PHP with Upload 4 14
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

705 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

19 Experts available now in Live!

Get 1:1 Help Now