Giter Site home page Giter Site logo

hamburgscleanest / guzzle-advanced-throttle Goto Github PK

View Code? Open in Web Editor NEW
129.0 7.0 17.0 407 KB

A Guzzle middleware that can throttle requests according to (multiple) defined rules. It is also possible to define a caching strategy, e.g. get the response from cache when the rate limit is exceeded or always get a cached value to spare your rate limits. Using wildcards in host names is also supported.

License: MIT License

PHP 100.00%
guzzle api middleware throttle throttle-requests rate-limiting rate-limit rate-limiter request-handler advanced

guzzle-advanced-throttle's People

Contributors

berenddeboer avatar dependabot-preview[bot] avatar eduardokum avatar huisman303 avatar lightguard avatar scrutinizer-auto-fixer avatar timopruesse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

guzzle-advanced-throttle's Issues

Problem with Laravel cache drivers

There currently is a problem with the cache drivers for Laravel / Illuminate. I already started working on it yesterday on the bus. Will hopefully be fixed today or tomorrow. It mainly affects Redis and Memcached.

Let script u_sleep() before 429 status showed up

Is it possible to make php script sleep milliseconds before got 429 response? Library calculates estimated time before 429, right? Why not sleep this time instead of throwing 429 exception?

Allow to use other implementations of StorageInterface and Cacheable

Is your feature request related to a problem? Please describe.
Currently, only those implementations within the project are recognized by Guzzle Advanced Throttle. If I create my own implementations I can't use them without having to patch/hack RequestLimitRuleset

Describe the solution you'd like
RequestLimitRuleset to instantiate and use a class if it implements/extends the proper interface/parent without throwing an error. If the class does not, it will throw an exception.

Describe alternatives you've considered
Maintaining my own patch

Additional context
I should get a PR out soon(TM) for this

Host definitions with wildcards

At the moment it is only possible to define a concrete host in the configuration file.
It should be possible to do something like this (pseudo wildcard format):

'host' => 'https://www.{locale}.test.com'

It would then match the following domains for example: https://www.en.test.com, https://www.de.test.com

Additionally it should be possible to place the wildcard anywhere. The following also needs to work:

'host' => 'https://www.test.com/{any}'

Would match: https://www.test.com/siteOne, https://www.test.com/siteTwo, etc.

Improve configuration (avoid duplication)

Turn this:

$rules = new RequestLimitRuleset([
        [
            'host'             => 'https://www.google.com',
            'max_requests'     => 20,
            'request_interval' => 1
        ],
        [
            'host'             => 'https://www.google.com',
            'max_requests'     => 100,
            'request_interval' => 120
        ]
    ]);

Into this:

$rules = new RequestLimitRuleset([
        'https://www.google.com' => [
            [
                'max_requests'     => 20,
                'request_interval' => 1
            ],
            [
                'max_requests'     => 100,
                'request_interval' => 120
            ]
        ]
    ]);

Essentially the key for each group becomes the host.
As this is a breaking change, it needs to be noted properly.

Respect request parameters for caching

At the moment responses are cached according to the requested URI. That's not really accurate and will return confusing results sometimes. The caching mechanism needs also to be based on the query parameters (or the request body for non GET requests).

So when https://www.test.de/test?query=true is cached it shouldn't be returned for a request to https://www.test.de/test?query=false. A cached response must only be returned when all the query parameters or the request bodies are the same.

Cache driver default doesn't use env CACHE_DRIVER

From the configuration file laravel-guzzle-throttle.php the driver is set to default as standard, however the default driver set by CACHE_DRIVER in the .env file was ignored and it rises a hamburgscleanest\GuzzleAdvancedThrottle\Exceptions\RedisDatabaseNotSetException.

Everything works correctly if I set the driver value to env('CACHE_DRIVER') instead of 'default'.

Why this behaviour?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.