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

226
Vistas
Cómo configurar el limitador de velocidad por segundo en Laravel versión 8

Cómo configurar el limitador de velocidad por segundo en Laravel 8 . Necesito configurar el limitador de velocidad por segundo en lugar de por minuto.

Limitador de velocidad (Laravel 8) - https://laravel.com/docs/8.x/routing#rate-limiting

En este momento, puedo usar el limitador de velocidad de Laravel durante minutos, horas, etc. Pero estoy tratando de lograr un limitador de velocidad por un segundo. Quiero limitar 25 solicitudes por segundo. (Clase de límite exportada de "Illuminate\Cache\RateLimiting\Limit")

Por favor revise el siguiente código que he usado

 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 () { ... }) ]; });

¿Hay alguna forma de limitar la tasa de 25 solicitudes por segundo?

Nota: también intenté agregar/cambiar funciones en Illuminate\Cache\RateLimiting\Limit, donde intenté alterar la función por minuto. Gracias de antemano.

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

0

<?php namespace App\Http\Cache; class Limit extends \Illuminate\Cache\RateLimiting\Limit { /** * Create a new limit instance. * * @param mixed|string $key * @param int $maxAttempts * @param int|float $decayMinutes * @return void */ public function __construct($key = '', int $maxAttempts = 60, $decayMinutes = 1) { $this->key = $key; $this->maxAttempts = $maxAttempts; $this->decayMinutes = $decayMinutes; } /** * Create a new rate limit using seconds as decay time. * * @param int $decaySeconds * @param int $maxAttempts * @return static */ public static function perSeconds($decaySeconds, $maxAttempts) { return new static('', $maxAttempts, $decaySeconds/60.0); } }

Puede redefinir la clase Límite

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