PHP code example of partimate / throttlemate

1. Go to this page and download the library: Download partimate/throttlemate 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/ */

    

partimate / throttlemate example snippets


use PartiMate\ThrottleMate\AdaptiveThrottler;

$result = AdaptiveThrottler::make()
    ->throttle(fn () => 'Process Request', 'api:request', 100, 60);

$result = AdaptiveThrottler::make('cache', true)
    ->throttle(fn () => 'Fetch User Data', 'user:fetch', 50, 30);

$result = AdaptiveThrottler::make('queue', true)
    ->throttle(fn () => 'Send Email', 'email:send', 100, 60);

Route::get('/api/data', [DataController::class, 'index'])->middleware('throttle.mate');

return [
    'limit' => 200, // Requests per minute
    'ttl' => 120,  // Expire time in seconds
];