Kthrottler Kohana module as a composer package
This package is auto-updated.
Last update: 2022-11-06 14:59:39 UTC
KThrottler is an easy to use Kohana module to quickly throttle application actions based on configurable duration and limit.
Brought to you by Wuit.
- Easy to use, easy to configure
- Supports Kohana v3
- Kohana's built-in DB module
git clone git://github.com/fredwu/kthrottler.git
In your bootstrap file (
application/bootstrap.php), enable KThrottler like this:
Kohana::modules(array( 'database' => MODPATH.'database', 'kthrottler' => MODPATH.'kthrottler', ));
kthrottler_logs_db.sql file supplied.
The configuration file is located at
config/kthrottler.php. Please copy it to your
The configuration array looks like this:
return array ( 'mail' => array ( 'duration' => '1 hour', 'limit' => 10, ), );
You can add as many configuration elements as you like, just make sure you label them properly (i.e. like
In the example, we are setting the
Now we will need to register the actions so they are recorded in the database.
To simply run an action, in your app (presumably somewhere in the controller), do this:
KThrottler::actions()->run() will return true or false depending on whether or not the action is being throttled.
KThrottler::actions()->run() has an alias
KThrottler::actions()->can_run() and a negative alias
Typically, we would want to produce feedback to the user when an action is throttled, you can do so by:
if (`KThrottler::actions()->cannot_run('mail')`) // tell the user that this action is not performed end
KThrottler::actions()->run() also takes an optional reference parameter:
The reference parameter is very useful because we can track and throttle the action based on a reference, such as a user. The parameter accepts a String, an Integer or an ORM object.
KThrottler::actions()->run() and its aliases will perform the action when possible. If you only want to check to see if an action can be performed, you can do this:
KThrottler::actions()->can_be_run() returns true or false without performing the action, and it also has a negative alias,