Jump to content


PHP Capping script?

  • Please log in to reply
4 replies to this topic

#1 deltablaze

  • Members
  • Pip
  • Newbie
  • 3 posts

Posted 26 February 2006 - 12:48 PM

Hey guys! I own an anime site, which people can download anime media from, it uses about 500GB a month. Anyways, loads of people were downloading and apache simply cannot handle all the requests, thus no pages load which makes the server really...well not working. I was wondering if anybody knows how to make or a script that can cap how many downloads people can download at a time.

#2 only one

only one
  • Members
  • PipPipPip
  • Advanced Member
  • 437 posts
  • LocationNetherlands

Posted 03 February 2007 - 11:26 PM

ill get you started
what you want is something that stores the time someone sterted downloading something in a database,
let them fill in a form that lets them select their connection speed, then find out a sort of avarage download time

now you want something like

//current time
$currenttime = date(YmdHis); // visit 'http://nl2.php.net/date'
//their ip
$downloadtime = $currentime + their avarge download time; 
//insert it into your database
mysql_query(INSERT INTO downloaders `downloadtime`, `ip` VALUES '$downloadtime', '$ip');

then i dont know how your site works but heres the code for retrieving it

//retreive stuff from databse
$time = date(YmdHis) + 50; //gives them 50 minutes from the hour to download it, if its any greater than 10 past the hour this doesnt always work very well, but this is only very basic....
$query = mysql_query("SELECT downloadtime FROM dowloaders WHERE downloadtime > $time") or die(mysql_error());
$row = mysql_fetch_array($query);
//allows no more than 10 peaople at once to download it
$num_rows = mysql_num_rows($query);
if($num_rows>10){ echo "currently unavailable"; }
else { echo "<a href=download url>Click here to download</a>"; }

this wont work!
Did you let the dogs out?


#3 JasonLewis

  • Members
  • PipPipPip
  • Advanced Member
  • 3,351 posts
  • LocationVictoria, Australia

Posted 03 February 2007 - 11:41 PM

i've never done something like this but you would have to do something like what only one has. you would have to store the users IP as well.
i am pretty sure you would have to find an average download time. although only one's code is very badly done, no offence.
Good luck with your coding.
Jason / ProjectFear / Jaysonic

#4 only one

only one
  • Members
  • PipPipPip
  • Advanced Member
  • 437 posts
  • LocationNetherlands

Posted 04 February 2007 - 09:11 AM

hey i said it was basic...
Did you let the dogs out?


#5 .josh

  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 04 February 2007 - 09:21 AM

Yeah...I'm not even going to get into how silly that code is...no offense man, but seriously...

Create a login system.  Force users to login.  Obfuscate the files by using a file id system.  Allow only x amount of downloads or x amount of bytes to be downloaded per x amount of time, per user, by storing those numbers in the database and associating them with the user info you have from the login system. 

Break that down one sentence at a time and start looking for some tutorials and put it all together.  Also look into hosting the files on other servers.  Get all those people who are willing to download your stuff to be willing to donate their own bandwidth, or give you some money to buy better hosting.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users