e-th0mas Posted March 12, 2012 Share Posted March 12, 2012 Hi all, I'm trying to make a PHP script that downloads a file off a remote FTP server and serves the file to the visitor with a limited download speed. Right now I'm using fopen like this: $path = "ftp://".$username.":".$password."@".$server."/"; $fullPath = ($path.$fileName); $speed = 400; // 400 kb/s download rate header("Cache-control: private"); header("Content-Type: application/octet-stream"); //header("Content-Length: ".filesize($fullPath)); header("Content-Disposition: filename=\"".$fileName."\""); flush(); $fd = fopen($fullPath, "r"); while(!feof($fd)) { echo fread($fd, round($speed*1024)); flush(); sleep(1); } fclose ($fd); The file does download but with the wrong speed (8kb/s), does anyone know why? When I run the same code with a local file instead of a file on FTP it works fine and downloads at the speed I set it to.. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/258773-download-file-over-ftp/ Share on other sites More sharing options...
requinix Posted March 12, 2012 Share Posted March 12, 2012 There might be a bottleneck downloading the file from FTP. Can you tell how fast that connection is? Is it about 8KB/s? When you're downloading the file yourself, does the speed vary or is it constant? Quote Link to comment https://forums.phpfreaks.com/topic/258773-download-file-over-ftp/#findComment-1326581 Share on other sites More sharing options...
cpd Posted March 12, 2012 Share Posted March 12, 2012 Read and learn http://php.net/manual/en/book.ftp.php Far more efficient in my opinion. Quote Link to comment https://forums.phpfreaks.com/topic/258773-download-file-over-ftp/#findComment-1326582 Share on other sites More sharing options...
e-th0mas Posted March 12, 2012 Author Share Posted March 12, 2012 There might be a bottleneck downloading the file from FTP. Can you tell how fast that connection is? Is it about 8KB/s? When you're downloading the file yourself, does the speed vary or is it constant? When using the code in my first post it downloads around 8KB/s. When I comment out sleep(1); it downloads at full speed, as it normally would when I download it directly myself. However by doing this I can't limit the download speed anymore... are there any alternative ways to achieve this? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/258773-download-file-over-ftp/#findComment-1326584 Share on other sites More sharing options...
e-th0mas Posted March 12, 2012 Author Share Posted March 12, 2012 Read and learn http://php.net/manual/en/book.ftp.php Far more efficient in my opinion. I looked into that, but I couldn't figure out how to limit the download speed using those functions. Quote Link to comment https://forums.phpfreaks.com/topic/258773-download-file-over-ftp/#findComment-1326585 Share on other sites More sharing options...
e-th0mas Posted March 14, 2012 Author Share Posted March 14, 2012 Anyone? Sorry for the bump, but still looking for an answer... Quote Link to comment https://forums.phpfreaks.com/topic/258773-download-file-over-ftp/#findComment-1327401 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.