Created
October 27, 2014 20:23
-
-
Save CaporalDead/ad2aedca7d4291959b9a to your computer and use it in GitHub Desktop.
Api limit with Laravel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Route::filter('api.limit', function() { | |
$key = sprintf('api:%s', Auth::user()->api_key); | |
// On crée le cache | |
apc_add($key, 0, 60 * 60); | |
// On incrément l'appel de 1 | |
$count = apc_inc($key); | |
if ($count > Config::get('api.requests_per_hour')) { | |
App::abort(403, 'Hourly request limit exceeded'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment