} // Don't start generating the image if the derivative already exists or if
// generation is in progress in another thread.
if (!
file_exists($derivative_uri)) { $lock_name = 'image_style_deliver:' .
$image_style->
id() . ':' . Crypt::
hashBase64($image_uri);
$lock_acquired =
$this->lock->
acquire($lock_name);
if (!
$lock_acquired) { // Tell client to retry again in 3 seconds. Currently no browsers are
// known to support Retry-After.
throw new ServiceUnavailableHttpException(3, 'Image generation in progress. Try again shortly.'
);
} } // Try to generate the image, unless another thread just did it while we
// were acquiring the lock.
$success =
file_exists($derivative_uri) ||
$image_style->
createDerivative($image_uri,
$derivative_uri);
if (!
empty($lock_acquired)) { $this->lock->
release($lock_name);
}