You are here

public function GeocoderThrottle::waitForAvailability in Geocoder 8.3

Sleeps until the throttle rate is not reached anymore.

Parameters

string $key: An identifier for the service where we send the requests.

array|null $throttle_info: An associative array with:

  • period: in seconds
  • limit: number of requests allowed in the period

or null not to limit the requests.

Return value

void|NULL

Overrides GeocoderThrottleInterface::waitForAvailability

File

src/GeocoderThrottle.php, line 41

Class

GeocoderThrottle
Provides a throttle mecanism for geocoder requests.

Namespace

Drupal\geocoder

Code

public function waitForAvailability(string $key, array $throttle_info = []) {

  // Use throttle info if set.
  if (isset($throttle_info['limit']) && isset($throttle_info['period'])) {

    // The throttle mechanism uses milliseconds, so we convert the argument
    // and convert back the result as sleep() uses seconds.
    $time_to_wait = $this->throttle
      ->throttle($key, $throttle_info['limit'], $throttle_info['period'] * 1000);
    sleep($time_to_wait / 1000);
  }
}