PHP code example of alexpts / php-rate-limiter

1. Go to this page and download the library: Download alexpts/php-rate-limiter 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/ */

    

alexpts / php-rate-limiter example snippets




use PTS\NextRouter\Router;
use PTS\RateLimiter\Adapter\MemoryAdapter;
use PTS\RateLimiter\Limiter;
use PTS\RateLimiter\RateLimitMiddleware;
use Zend\Diactoros\Response\JsonResponse;
use Zend\Diactoros\ServerRequestFactory;

ware->setKeyAttr('ip');

$psr15Runner = new Next(); // relay or other psr-15 runner
$psr15Runner->getStoreLayers()->middleware($limiterMiddleware);

$psr7Request = ServerRequestFactory::fromGlobals();
$response = $psr15Runner->handle($psr7Request);

// flush response or other
// ...