Bandwidth Script help please!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
naissa
Forum Newbie
Posts: 4
Joined: Sat Jan 03, 2004 4:35 pm

Bandwidth Script help please!

Post by naissa »

Hello,
I am trying to write a bandwidth php scrp, that obtains the bandwidth of each user, an automatically disables the user who goes over an amount of bandwidth.

The script should be automatic.

Please reply if you have any ideas how I can write it. Thanks
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

Use output buffering, then before you ouput your data measure the length in bytes, then output the content.
After you output the content write to the database about which user the content was rendered for and the length in bytes, at the beginning of each page view obtain the sum of a user's bandwidth from the database and if it is greater then your threshold, output an error message and terminate the script with a die();
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

i would add the date time to that as well so each time the page is requested it does what jshpro2 said and writes to the db but it should count the amount of bandwidth that that user used since a certain time so you can set limits like a user can only use 1 mgb every 5 minutes or somthing, make the restrictions and time whatever you want but if you just go and update the db with the new amount a user will quickly be out of bandwidth because there is no way to have the badwith meter go back down for that user
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

Unless he's going by bandwidth / month in which case you just use cron to truncate the table every month. You could even do both, set an hourly (using timestamps) and monthly limit.
Post Reply