Coder Social home page Coder Social logo

Comments (4)

Baspa avatar Baspa commented on June 15, 2024 1

Hmm I don't think that's too low at all. But I think because it's grouped we reach the limit too fast. I'm currently thinking about building some throttle mechanism into the package so you can configure the maximum amount of requests done per minute. You're probably not the only one using the throttle middleware so we should find a solution for this.

I will try to find a good solution for this, if you have any ideas in the meantime please let me know 👍🏼

from laravel-seo-scanner.

Baspa avatar Baspa commented on June 15, 2024

Only one request is made for each url, so it should only be visited once by the scan. Can you tell me how many requests can be made each minute to your routes and how many requests you receive within that minute?

from laravel-seo-scanner.

MuriloChianfa avatar MuriloChianfa commented on June 15, 2024

apparently the throttle middleware groups some routes when used with the Route::group function, thus forcing the route group.
I defined the access limit as 30:1 (30 requests every 1 minute) but I have about 40 routes protected by the same throttle middleware to avoid flooding, do you think that is too low?

from laravel-seo-scanner.

Baspa avatar Baspa commented on June 15, 2024

I think the problem is with the isBrokenLink method which makes a request with curl to determine if the link is broken:

if (! function_exists('isBrokenLink')) {
    function isBrokenLink(string $url): bool
    {
        $statusCode = (string) getRemoteStatus($url);

        if (str_starts_with($statusCode, '4') || str_starts_with($statusCode, '5') || $statusCode === '0') {
            return true;
        }

        return false;
    }
}

if (! function_exists('getRemoteStatus')) {
    function getRemoteStatus(string $url): int
    {
        return cache()->driver(config('seo.cache.driver'))->tags('seo')->rememberForever($url, function () use ($url) {
            $ch = curl_init($url);

            $options = [
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_HEADER => true,
                CURLOPT_NOBODY => true,
                CURLOPT_TIMEOUT => 10,
                CURLOPT_FOLLOWLOCATION,
            ];

            if (app()->runningUnitTests()) {
                $options[CURLOPT_SSL_VERIFYHOST] = false;
                $options[CURLOPT_SSL_VERIFYPEER] = false;
                $options[CURLOPT_SSL_VERIFYSTATUS] = false;
            }

            curl_setopt_array($ch, $options);
            curl_exec($ch);

            $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

            curl_close($ch);

            return $statusCode;
        });
    }
}

Possible solutions

  • We could use Guzzle Advanced Throttle. I don't know if using Guzzle slows down making the requests, I should check that first.
  • Use some sort of queue mechanism in the package which can limit the number of requests made at any given time.

from laravel-seo-scanner.

Related Issues (9)

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.