Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
A Question about some php functions
Old 10-24-2008, 04:02 PM A Question about some php functions
Junior Talker

Posts: 2
Trades: 0
Greetings

I want to limit the speed of download from my site. And want to prevent any client from downloading more than one file at the same time.

To do this.. I have written a PHP script (after searching the web and php.net). which uses these functions (and others):
fopen() - fread() - fwrite() - fclose() - flush()
To control the speed of downloading process.. fread() function was used. like this:

PHP Code:
$fp fopen("$file",'r');

        
//start buffered download

        
while(!feof($fp) && connection_status() == 0)

                {     

            
//reset time limit for big files

            
set_time_limit(0);

            
$_fread fread($fp1024*$speed);

            print(
$_fread);

            
flush();

            
sleep(1);

                }   

                
fclose($fp); 
My question is: is there any problem to use this script? will it make any problem to the server or increase the load? will it affect the CPU resources?
Notice that there is many visitors are downloading from my site. I'll apply this script on all (rar, pdf, zip) files in my site.

Please tell me whether to use this script or not. If not: what is the alternative? How can I perform this limitation?

My host provider is: 1&1

Thank you in advance
Leopardo is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-25-2008, 01:18 AM Re: A Question about some php functions
Experienced Talker

Posts: 38
Name: Alan
Trades: 0
The script should not cause any server side problems but I am real confused as to why you need to limit the speed of a download? I mean, bandwidth is band width no matter what speed it is used.
__________________

Please login or register to view this content. Registration is FREE
alhefner is offline
Reply With Quote
View Public Profile Visit alhefner's homepage!
 
Old 10-25-2008, 07:40 PM Re: A Question about some php functions
Junior Talker

Posts: 2
Trades: 0
Thank you `alhefner`

Are you sure it will not cause any problems? Please confirm. Because many of my friends said it will destroy the server (I'm joking but they said it will cause a huge load!)

Quote:
but I am real confused as to why you need to limit the speed of a download? I mean, bandwidth is band width no matter what speed it is used
I don't want only to limit the speed. also I want to prevent downloading more than one file at the same time!

The reason is: I have 2000Gb per month. If the download is available at max speed that client can reach: the 2000Gb will end tomorrow!
And if I allowed each user to download more than one file.. it will cause more load at the sever.. many times the hosting provider sent to me that the folder (files) caused a (crash) in the server! and told me to purchase a dedicated server!
Leopardo is offline
Reply With Quote
View Public Profile
 
Old 10-27-2008, 06:28 AM Re: A Question about some php functions
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
You should not limit bandwidth with php scripts, it is absolute nonsense. You should limit bandwidth either with some apache module like mod_bwshare or by means of external software like nginx or lighttpd (frontend light-weight webserver) or squid (caching proxy). Using scripts is fine until you get 100 simultaneous downloads.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 10-27-2008, 06:45 AM Re: A Question about some php functions
hamesy's Avatar
Webmaster Talker

Posts: 639
Name: Steve
Location: Birmingham, England
Trades: 0
If your going to limit the number of maximum connections per user, then you should really do it using your server software, ie apache.

If you hosting provider says purchase a dedicated server, then I really think you should. It will provide a better service for your users and also your host may decided to stop hosting your website if its responsible for crashing the servers.
__________________
Hamesy

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Last edited by hamesy; 10-27-2008 at 06:47 AM..
hamesy is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to A Question about some php functions
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15609 seconds with 12 queries