You are here

function _amazons3_image_wait_transfer in AmazonS3 7.2

Wait for an image to appear in a directory, and transfer it when it appears.

Parameters

string $uri: The image URI to transfer.

Return value

bool FALSE if the image was not transferred.

1 call to _amazons3_image_wait_transfer()
amazons3_image_deliver in ./amazons3.module
Image delivery callback that uploads a derivative to S3.

File

./amazons3.module, line 270
Hook implementations for the AmazonS3 module.

Code

function _amazons3_image_wait_transfer($uri) {

  // Another process is trying to create the file on S3. S3 uploads can
  // still be slow, so we wait for the temporary file to exist and serve
  // that.
  $tries = 0;
  while ($tries < 4 && !file_exists($uri)) {
    usleep(500000);
    $tries++;
  }

  // If the file doesn't exist, it either means we had a stale lock, or the
  // other process died and couldn't create the image style. In that case,
  // we fall through and try to create the derivative without acquiring the
  // lock.
  if (file_exists($uri)) {
    $image = amazons3_image_load($uri);
    file_transfer($uri, array(
      'Content-Type' => $image->info['mime_type'],
      'Content-Length' => $image->info['file_size'],
    ));
  }
  return FALSE;
}