473,320 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to define the speed limit for downloads from FTP?

Hi, I'm tring to code a download page. But I have to list the files from multiple ftp accounts. So I took the code php.net to limit the speed and adapted that for ftp.

But I have a problem when the parameter in sleep is 1 the download speed stuck at 10kb. but when I change it to a number less then 1. the speed becomes unlimited.

I can't define the speed limit in any case. What can I do to overcome this problem.

My code:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     $fileName=$_GET['go'];
  3.     $ftp="127.0.0.1";
  4.     $user="Admin";
  5.     $pass="12";
  6.     $path="files/";
  7.  
  8.     $speed = 20000; 
  9.  
  10.     $url="ftp://$user:$pass@$ftp/$path$fileName";
  11.     if(file_exists($url) && is_file($url))
  12.     {
  13.  
  14.         header('Content-Type: application/octet-stream'); 
  15.         header('Content-Length: '.filesize($url));
  16.         header('Content-Disposition: filename='.$fileName);
  17.         flush();
  18.         $file = fopen($url, "r");
  19.         while(!feof($file)){
  20.             echo fread($file, round($speed*1024));;    
  21.             flush();
  22.             sleep(1);
  23.         }
  24.         fclose($file);
  25.     }
  26.     else {
  27.         die('Error: The file '.$local_file.' does not exist!');
  28.     }
  29.  
Thanks for your help.
Feb 6 '11 #1
0 1005

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Andrey | last post by:
How to define speed connection modem (Internet) in javascript?
6
by: David Young | last post by:
Hello all, I'm quite new to C# (< 6 months) but really love it and is my language of choice ..... but I have one question I've not been able to find out ..... In C++ a #define label in one...
5
by: Earl Teigrob | last post by:
My company sells software and wants to provide downloadable product. Some of these downloads will be full CD's of over 550M I had everything working fine using Response.filewrite() but when we...
9
by: James Macbell | last post by:
I think I have pushed ASP.NET to the limit, I am not sure if I have done anything wrong in the code because I am trying to make 2 pieces of code (C# vs PHP) using the same algorithm. Anyways, here...
12
by: chipgraphics | last post by:
:confused::confused: I have been on the quest to find a php script that can serve files for downloads and limit the speed at which the file is transfered to the user. I want a faster download...
102
by: tom fredriksen | last post by:
Hi I was doing a simple test of the speed of a "maths" operation and when I tested it I found that removing the loop that initialises the data array for the operation caused the whole program to...
1
by: bigpoppa | last post by:
Hey, I need a script that will limit download speed and I want it integrated into the script I am using below. The script below forces downloads and hides url paths and logs stastics of downloads and...
0
by: toka | last post by:
Hello, I use HttpWebRequest/HttpWebResponse to retrieve a file from weberver. I retrieve it as a Stream and write to file. But this simple method uses all available network bandwidth. How can I...
7
Jezternz
by: Jezternz | last post by:
Ok I have a registration/permissions system setup, and I want to limit different user groups to only allow for an amount of downloads. (and non-logged in users to not have the ability to download...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.