I am creating a bandwidth quota program in PHP, however I am finding that to create it with PHP is a bit hard. As an example of what I am trying to do, the user can download 10GB per day, and after they have reached the bandwidth cap the user should be unable to connect.

I would like to find a program to record how much bandwidth the remote host uses (per remote IP address and remote port). The remote port is important to be able to identify that the user behind a NAT has downloaded the file.

I would like to know if it's possible to monitor a remote host not by IP but by username? Can I track how much bandwidth the user uses, making this more simple? It's something like the rapidshare trafficshare system. I need a system like this!

Can you give me some ideas and pointers how to create a system like this using PHP or any scripting language? I really appreciate it!


Solution 1:

IP ports have absolutely nothing to do with the problem you describe

Forget about IP addresses. Many, many years ago when every computer on the internet had a fixed, public IP address it would have worked. But that time is long gone.

One user can connect from multiple client addresses. Multiple users can connect from a single ip address. Restrict all access to authenticated users and run all the downloads through a PHP script which

1) picks up the authenticated user from the session and redirects to login on failure.
2) identifies if they've sufficient quota to download the requested file or redirects to paid package page
3) updates the quota used at points throughout the download

C.

Solution 2:

This is an old question, so I guess the OP is unlikely to still be looking for an answer. But I will add some input for the benefit of future visitors.

The internet is awash with small single-file scripts to control byte consumption (amount) and bandwidth (speed). However I haven't found any PHP systems that are (a) designed as an application rather than a single script, and (b) also open-source. I've therefore built my own, which I've released as an alpha for early feedback.

Anyone is welcome to try the software and to suggest features - it is free and open source. With a bit of patience at the install stage it is usable already, but it is probably not suitable for PHP beginners yet. Anyone who is building their own system of this kind is welcome to delve into the source for ideas, or to build on top of what I have already.