I want to create premium membership plans in my wordpress site in a way that for example gold users can download files without any limits but regular users have to download files at maximum 200KB/s speed.
It's simple to save a cookie when user logins in wordpress (using setcookie() function according to this), So it seems best way to achieve my goal is to filter users based on cookie.
I've searched and found mod_qos apache module, It can limit bandwidth and has a Privileged Users option but I don't know how to use it to exclude premium users from limitations. Provided docs are not detailed enough.
There are other modules like mod_cband and mod_ratelimit and others but none of them can filter users based on cookie (or at least I couldn't figure out a way to do so)
Other workaround is to filter users based on IP and use tc and iptables to limit bandwidth (like its done for open vpn here). But it seems difficult because you must execute shell commands for every user login and add user IP to high bandwidth group.
Note: I have two seperate servers, one is a web host with cpanel which my wordpress site runs on and other is a vps which I host my files.
Excuse my bad english or diction, this is my first question in stackoverflow. Thanks in advance.
After more research I have found the solution myself:
First line checks if a cookie named "foo" with the value "bar" exists, if so toggles environment variable "IsVIP". Second line applies download speed limit if "IsVIP" has not set to true.
sources:
https://sourceforge.net/p/mod-qos/discussion/697421/thread/82a85ab2
https://serverfault.com/questions/541458/how-do-you-use-apache-setenvif-with-cookie-values
http://mod-qos.sourceforge.net/