Closed Thread Icon

Topic awaiting preservation: bandwidth limitation script (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12718" title="Pages that link to Topic awaiting preservation: bandwidth limitation script (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: bandwidth limitation script <span class="small">(Page 1 of 1)</span>\

 
smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 05-06-2003 20:15

ok, my site is a gallery site for many peoples work, including movie projects. My new sponsor has given me a 5GB per month limit on bandwidth, after which I will need to pay for every MB over. I dislike this and have asked them if they could just cap it so that a 404 type page is displayed saying my bandwidth has been exceeded, they said no.

So, how can I do something similar without getting my host to fiddle with their server to much?

My server is Apache I think (maybe IIS5) - but it's running PHP and MySQL and maybe PERL and CGI.

I have a PHP/MySQL script created by a nice guy just for me, it requires me to enter the files of my site and their sizes into a MySQL database and then put code on eacsh download which checks the databse and sees if the preset limit has been reached for that day, if it has it denies the download - it seems an awkward and time consuming way to do it tho, is there an easier way?

Please help

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 05-06-2003 21:00

What I would do is just put all your big bandwidth hogging projects on one page (or a few pages) and then write a small php script for the page that checks your usage and then either display's or doesn't display the page based on where you are at for the month.

This is assuming you have a file somewhere you can parse to get your usage stats for the month somewhere.



.:[ Never resist a perfect moment ]:.

smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 05-06-2003 21:34

what file would i need to parse to get my usage stats? i asked a guy about using raw log files if i have access to them and he laughed at me and said my server would fry.

also putting all the content on one page isn't really convenient, isn't there a way to monitor directory (including subdirectory) traffic?

visit my CryoKinesis Online Gallery

Piper
Paranoid (IV) Inmate

From: California
Insane since: Jun 2000

posted posted 05-07-2003 03:30

Hi smonkey,

This is really something that should be handled at the server level. I kow that mod_throttle does this for Apache. Unfortunately, this will require help from your host.

To get your usage stats, you need to parse your access.log (assuming your server is Apache). As long as the logs are rotated often, parsing them with perl wont bother the server too much. I wouldn't parse the log on every request though. I'd set up a script to run on a cron job that checked the logs every 30 to 60 minutes. If you don't get that much traffic, you can run the script once a day to cut down the server load. If you reach or exced the limit, then disabled the page/directory with .htaccess.

Regards,
Charlie

smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 05-07-2003 19:31

cheers charlie/piper,

sounds good, how do i do the cron jobs and the parsing of logs and all the other bits?

visit my CryoKinesis Online Gallery

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 05-07-2003 20:44

hey hey hey, we can't do all the work for you!

Accessing files with perl

Here's the formats for apache log files (note usually the file size will be the last numbers on a line)

cron tutorial <-- this will depend on your host so you may want to check with them about how to do this on thier servers.

Start with trying to see if you can get the total of all your access log file sizes and go from there.




.:[ Never resist a perfect moment ]:.

Piper
Paranoid (IV) Inmate

From: California
Insane since: Jun 2000

posted posted 05-07-2003 21:02

Like bitdamaged said, we can't do it for you. He did post some very useful links to help you get started. If you give it a try and get stumped, post your code here and people will help. Also, if you post a few lines from your access log, I will help you out with a regex to break up the parts.

This should actually be a pretty simple script to code if you're just starting out.

~Charlie

smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 05-08-2003 01:01

It was worth a shot.

Ok well from what I've read a think with a few hours to a day or so I can maybe figure out how to do this.

Piper, I may take you up on the offer for help with a regular expression (I like them, kinda like algebraic formulas, although I don't like them much) - my knowledge and skills in this area is ok but limited and I tend to make mistakes a lot.

Thanks for the links.

Can anyone recommend a good 'basic-to-cool' level javascript book and maybe one on php, another on mysql (or both combined), and maybe one for perl too (why do I need to know perl? what is it good for compared to php? is cgi really needed anymore? what the hell is python and ruby and all the other weird scripts for? why so many?). I find ebooks hard to concentrate on and fully absorb.

Well that last bit is nearly a worthy post in it's own right, dunno what forum it'd go in tho.

Piper
Paranoid (IV) Inmate

From: California
Insane since: Jun 2000

posted posted 05-08-2003 02:45
quote:
why do I need to know perl? what is it good for compared to php?



Honestly, you would be better off with php if you are strictly doing web stuff. What I reccomended above about running a script via cron to parse your access.log is more suited to perl than php but either will work. The learning curve for php is much shorter.

I'm sure someone will have some links to a few good php and mysql books. In fact, head over to the FAQ and search around, I seem to remember something like this in the FAQ somewhere. (links at the top of the page)

~Charlie

Petskull
Maniac (V) Mad Scientist

From: 127 Halcyon Road, Marenia, Atlantis
Insane since: Aug 2000

posted posted 05-08-2003 03:23

bit, this link fucking rocks!
Perls before Swine

thanks loads!


Code - CGI - links - DHTML - Javascript - Perl - programming - Magic - http://www.twistedport.com
ICQ: 67751342

« BackwardsOnwards »

Show Forum Drop Down Menu