Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

932
Vistas
How to set the rate limiter for per second in Laravel version 8

How to set the rate limiter per second in Laravel 8. I need to set the rate limiter per second instead of per minute.

Rate Limiter (Laravel 8) - https://laravel.com/docs/8.x/routing#rate-limiting

Right now I'm able to use Laravel's rate limiter for minutes, hours, etc. But I'm trying to achieve a rate limiter for a second. I want to limit 25 requests per sec. (Exported Limit class from "Illuminate\Cache\RateLimiting\Limit")

Please check the following code which I have used

RateLimiter::for('api', function (Request $request) {
        return [
            // Rate limiter based on Client IP Address
            Limit::perMinute(env('IP_ADDR_RATE_LIMITER_PER_MINUTE', 60))->by($request->ip())->response(function () {
                ....
            }),
            // Rate limiter based on API key/User
            Limit::perMinute(env('API_KEY_RATE_LIMITER_PER_MINUTE', 60))->by($request->input('key'))->response(function () {
                ...
            })
        ];
    });

Is there any way to rate-limit 25 requests per second?

Note: also tried adding/changing functions in Illuminate\Cache\RateLimiting\Limit, where I tried altering the per minute function. Thanks in Advance.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You can redefine the \Illuminate\Cache\RateLimiting\Limit class to allow the $perSeconds attribute of float type and to add a new perSeconds() function.

/**
     * Create a new rate limit using seconds as decay time.
     *
     * @param  int  $maxAttempts
     * @param  int  $decaySeconds
     * @return static
     */
    public static function perSeconds($decaySeconds, $maxAttempts)
    {
        return new static('', $maxAttempts, $decaySeconds/60.0);
    }

over 4 years ago · Santiago Trujillo Denunciar

0

It is possible to configure Laravel 8 RateLimitter to allow for req/seconds

Here is the example you are looking for: https://learn2torials.com/thread/how-to-set-the-rate-limiter-for-per-second-in-laravel-version-8

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda