PHP code example of muhamed-didovic / throttle

1. Go to this page and download the library: Download muhamed-didovic/throttle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

muhamed-didovic / throttle example snippets


$config = [
    'cache.path' => '/tmp',
    'cache.driver' => 'file',
    'limit' => 10,
    'time' => 1,
    'routes' => [
        [
            'url' => '/signup',
            'limit' => 10
        ],
        [
            'url' => '/signin',
            'limit' => 3,
        ],
        [
            'url' => '/signin',
            'limit' => 2,
            'method' => 'POST'
        ]
    ]
];

$throttle = (new ThrottleApp($config))->getThrottle();

if (!$throttle->attempt($request)) {
    echo "Rate limit exceeded. Please wait " . 60 . " sec."; die;
}