nikolaposa / rate-limit

🚔 General purpose rate limiter implementation.
MIT License
269 stars 47 forks source link

Fatal error: Uncaught Error: Class 'RateLimit\Rate' not found #54

Open cafefars opened 2 years ago

cafefars commented 2 years ago

Please guide me how to fix this error

Fatal error: Uncaught Error: Class 'RateLimit\Rate' not found

`<?php use RateLimit\Exception\LimitExceeded; use RateLimit\Rate; use RateLimit\RedisRateLimiter; use Redis; require_once("./vendor/autoload.php"); $rateLimiter = new RedisRateLimiter(Rate::perMinute(100), new Redis());

$apiKey = 'abc123';

try { $rateLimiter->limit($apiKey);

//on success

} catch (LimitExceeded $exception) { //on limit exceeded }`

nikolaposa commented 2 years ago

Hi, which version are you using?

Also, put require_once("./vendor/autoload.php"); at the top of your script, before use statements. Also, make sure that vendor/autoload.php really exists on that path, i.e. make sure you run composer install.

cafefars commented 2 years ago

php version is 7.4 and "nikolaposa/rate-limit": "^1.0"

As you said, I changed the script, but the error is still displayed

nikolaposa commented 2 years ago

Did you run composer install? Did you check whether this file ./vendor/autoload.php exists on that location on your machine?

cafefars commented 2 years ago

Yes, there is an autoload.php file in the ./vendor path I ran the composer install command again and it was ok

composer install Installing dependencies from lock file (including require-dev) Verifying lock file contents can be installed on current platform. Nothing to install, update or remove Generating autoload files

But still there is the following error Fatal error: Uncaught Error: Class 'RateLimit\Rate' not found

nikolaposa commented 2 years ago

Well that's very weird, seems like some basic miss-configuration in your setup. Class loading is a basic thing, no one else complained with this type of issues.