You are here

function _cdn_devel_page_stats in CDN 6

Same name and namespace in other branches
  1. 5 cdn.module \_cdn_devel_page_stats()
  2. 6.2 cdn.stats.inc \_cdn_devel_page_stats()
  3. 7.2 cdn.stats.inc \_cdn_devel_page_stats()

Collects per-page CDN integration statistics.

Parameters

$file: The local file path.

$file_cdn_url: The URL to the file on the CDN if it exists, FALSE otherwise.

$server: The server the file exists on.

$time: The time it took to get the current CDN URL.

Return value

Only if no parameters were passed: the collected statistics.

2 calls to _cdn_devel_page_stats()
cdn_exit in ./cdn.module
Implementation of hook_exit().
custom_file_url_rewrite in ./cdn.module

File

./cdn.stats.inc, line 26
Per-page CDN integration statistics functionality.

Code

function _cdn_devel_page_stats($file = FALSE, $file_cdn_url = FALSE, $server = FALSE, $time = FALSE) {
  static $files;
  static $file_count;
  static $cdn_file_count;
  static $synced_files_per_server_count;
  static $total_time;
  static $synced_files;
  static $unsynced_files;
  static $drupal_root_path;
  if (!isset($drupal_root_path)) {
    $drupal_root_path = dirname('.');
  }
  if (!isset($file_count)) {
    $files = array();
    $file_count = 0;
    $cdn_file_count = 0;
    $synced_files_per_server_count = array();
    $total_time = 0;
    $synced_files = array();
    $unsynced_files = array();
  }

  // If the function is called with parameters set, save the statistics. If no
  // parameters are passed, return the collected statistics.
  if ($file && !array_key_exists($file, $files)) {
    $files[$file] = TRUE;
    $file_count++;
    $total_time += $time;
    if ($file_cdn_url !== FALSE) {
      $cdn_file_count++;
      $synced_files[] = array(
        'file' => $file,
        'absolute path' => realpath($drupal_root_path . '/' . $file),
        'cdn_url' => $file_cdn_url,
        'server' => $server === FALSE ? '' : $server,
      );

      // $server is only set in advanced mode.
      if ($server !== FALSE) {
        if (!array_key_exists($server, $synced_files_per_server_count)) {
          $synced_files_per_server_count[$server] = 0;
        }
        $synced_files_per_server_count[$server]++;
      }
    }
    else {
      $unsynced_files[] = $file;
    }
  }
  elseif (!$file) {
    return array(
      $file_count,
      $cdn_file_count,
      $synced_files_per_server_count,
      $total_time,
      $synced_files,
      $unsynced_files,
    );
  }
}