Skip to content

Instantly share code, notes, and snippets.

@CaporalDead
Created October 27, 2014 20:23
Show Gist options
  • Save CaporalDead/ad2aedca7d4291959b9a to your computer and use it in GitHub Desktop.
Save CaporalDead/ad2aedca7d4291959b9a to your computer and use it in GitHub Desktop.
Api limit with Laravel
<?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