setAncestorClass(self::class) ->execute(); } /** * Throttle checks from executing too often. * * If you throttle a check like this, it will only execute once every 2.5 * seconds: * * if ($this->shouldThrottle('some.check', 2.5)) { * return; * } * * @param string $name Throttle key. * @param float $duration Duration in seconds. * @return bool True to throttle the check. */ protected function shouldThrottle($name, $duration) { $throttle = idx($this->throttles, $name, 0); $now = microtime(true); // If not enough time has elapsed, throttle the check. $elapsed = ($now - $throttle); if ($elapsed < $duration) { return true; } // Otherwise, mark the current time as the last time we ran the check, // then let it continue. $this->throttles[$name] = $now; return false; } }