Jump to content

Archived

This topic is now archived and is closed to further replies.

deltablaze

PHP Capping script?

Recommended Posts

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.
Thanks!

Share this post


Link to post
Share on other sites
[b]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[/b]
[code]
<?
//current time
$currenttime = date(YmdHis); // visit 'http://nl2.php.net/date'
//their ip
$ip=$_SERVER['REMOTE_ADDR'];
//calculations
$downloadtime = $currentime + their avarge download time;
//insert it into your database
mysql_query(INSERT INTO downloaders `downloadtime`, `ip` VALUES '$downloadtime', '$ip');
?>[/code]

[b]then i dont know how your site works but heres the code for retrieving it[/b]

[code]<?
//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>"; }
?>[/code]

[b][color=red]this wont work![/color][/b]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.