Limiting bandwith by querying mysql possible?

Hi, i haven’t found a solution regarding nginx, and it’s driving me
nuts…
what i’m trying to do is limit the bandwith for each user that i have in
a mysqlDB for some mp3.
I already have the DB , and i’ve been trying to implement this with
NginxXSendfile, but that doesn’t count traffic , just No. of downloads
by calling a php script, and the the php forwards to nginx the file
transparently…

this has raised a big amount of suport mails for my system, as the users
are…pretty ,well you know how they are…

so , i don’t have a clue how to do this , i have to really count the
traffic…

the situation it’s pretty bad as i have more webservers serving, and one
central DB…with a cluster…but it’s a mysql

what i don’t want to do is serve files with php, and of course
programming a module is not an option…C++ is pretty hard for me

Thank you for reading this post

Posted at Nginx Forum:

what i’m trying to do is limit the bandwith for each user that i have in a
mysqlDB for some mp3.
I already have the DB , and i’ve been trying to implement this with
NginxXSendfile, but that doesn’t count traffic , just No. of downloads by
calling a php script, and the the php forwards to nginx the file
transparently…

Did you try parsing access logs?

Best regards,
Piotr S. < [email protected] >

well parsing access logs, doesn’t do the trick because each time a user
tries to download a file, it actually calls my php script

then the php script forwards with header and NginxXSendfile the file,
then loses of course control…

so parsing logs won’t do any trick becase it’s the same effect

Posted at Nginx Forum:

well parsing access logs, doesn’t do the trick because each time a user
tries to download a file, it actually calls my php script

then the php script forwards with header and NginxXSendfile the file, then
loses of course control…

so parsing logs won’t do any trick becase it’s the same effect

Erm… In my opinion it does. You need to parse access logs for
accounting
(ie. how many bytes user X downloaded so far) and in your PHP script you
need to verify if user is still allowed to download the next file. You
simply don’t send X-Sendfile header when he’s not. It should be as easy
as
that.

Best regards,
Piotr S. < [email protected] >

On Tue, Dec 8, 2009 at 12:43 PM, partysoft [email protected] wrote:

Hi, i haven’t found a solution regarding nginx, and it’s driving me nuts…
what i’m trying to do is limit the bandwith for each user that i have in a mysqlDB for some mp3.
I already have the DB , and i’ve been trying to implement this with NginxXSendfile, but that doesn’t count traffic , just No. of downloads by calling a php script, and the the php forwards to nginx the file transparently…

this has raised a big amount of suport mails for my system, as the users are…pretty ,well you know how they are…

so , i don’t have a clue how to do this , i have to really count the traffic…

the situation it’s pretty bad as i have more webservers serving, and one central DB…with a cluster…but it’s a mysql

I think we can control the bandwidth in the ngx_drizzle module :slight_smile: But
you’ll have to use ngx_drizzle to access your mysql cluster, not from
php and not via libmysql.

what i don’t want to do is serve files with php, and of course programming a module is not an option…C++ is pretty hard for me

We’ll provide a config file option in the near future :slight_smile: And no PHP
nor C/C++ will be required here.

Cheers,
-agentzh

what i’m trying to do is limit the bandwith for each user that i have in
a mysqlDB for some mp3.

You might be able to look at the postaction handler. We have something
like this:

location /xyz {
  ...
  proxy_hide_header           X-Rate-User;
  post_action                 @ratepostaction;
}

location @ratepostaction {
  set $rateuser $upstream_http_x_rate_user;
  proxy_set_header RateUser $rateuser;
  proxy_set_header RateURI  "$host$request_uri";
  proxy_set_header RateBytes $body_bytes_sent;
  proxy_set_header RateIP $remote_addr;
  proxy_set_header RateStatus $upstream_status;
  proxy_pass_request_body off;
  proxy_pass_request_headers off;
  proxy_pass http://unix:/var/state/ratetrack/ratepostaction:;
}

To track used bandwidth for each user. The backend sets the X-Rate-User
header in the response, and there’s a separate daemon running that
listens on /var/state/ratetrack/ratepostaction to receive the rate data
events.

I’m not sure how this interacts with NginxXSendfile though…

Rob