You are here

function _cdn_basic_farfuture_generate_file in CDN 6.2

Same name and namespace in other branches
  1. 7.2 cdn.basic.farfuture.inc \_cdn_basic_farfuture_generate_file()

Perform a nested HTTP request to generate a file.

Parameters

$path: A path relative to the Drupal root (not urlencoded!) to the file that should be generated.

Return value

Whether the file was generated or not.

1 call to _cdn_basic_farfuture_generate_file()
cdn_file_url_alter in ./cdn.module
Implementation of hook_file_url_alter().

File

./cdn.basic.farfuture.inc, line 438
Far Future expiration setting for basic mode.

Code

function _cdn_basic_farfuture_generate_file($path) {

  // Check if there's a file to generate in the first place!
  if (!menu_get_item($path)) {
    return FALSE;
  }

  // While it should already be impossible to enter recursion because of the
  // above menu system check, we still want to detect this just to be safe.
  // This really can only happen if a file is missing and we try to generate
  // it and the request to generate the file itself triggers a 404, which
  // again references the file that is missing, and would thus again trigger a
  // 404, etc.
  // @see http://drupal.org/node/1417616#comment-5694960
  if (request_uri() == base_path() . $path) {
    watchdog('cdn', 'Recursion detected for %file!', array(
      '%file' => $path,
    ), WATCHDOG_ALERT);
    header('HTTP/1.1 404 Not Found');
    exit;
  }
  $url = $GLOBALS['base_url'] . '/' . drupal_urlencode($path);
  $headers = array(
    // Make sure we hit the server and do not end up with a stale
    // cached version.
    'Cache-Control' => 'no-cache',
    'Pragma' => 'no-cache',
  );
  drupal_http_request($url, $headers);
  $exists = file_exists($path);
  watchdog('cdn', 'Nested HTTP request to generate %file: %result (URL: %url, time: !time).', array(
    '!time' => (int) $_SERVER['REQUEST_TIME'],
    '%file' => $path,
    '%url' => $url,
    '%result' => $exists ? 'success' : 'failure',
  ), $exists ? WATCHDOG_NOTICE : WATCHDOG_CRITICAL);
  return $exists;
}