| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Per-page CDN integration statistics functionality.
|
| 7 |
*/
|
| 8 |
|
| 9 |
|
| 10 |
//----------------------------------------------------------------------------
|
| 11 |
// Private functions.
|
| 12 |
|
| 13 |
/**
|
| 14 |
* Collects per-page CDN integration statistics.
|
| 15 |
*
|
| 16 |
* @param $file
|
| 17 |
* The local file path.
|
| 18 |
* @param $file_cdn_url
|
| 19 |
* The URL to the file on the CDN if it exists, FALSE otherwise.
|
| 20 |
* @param $server
|
| 21 |
* The server the file exists on.
|
| 22 |
* @param $time
|
| 23 |
* The time it took to get the current CDN URL.
|
| 24 |
* @return
|
| 25 |
* Only if no parameters were passed: the collected statistics.
|
| 26 |
*/
|
| 27 |
function _cdn_devel_page_stats($file = FALSE, $file_cdn_url = FALSE, $server = FALSE, $time = FALSE) {
|
| 28 |
static $files;
|
| 29 |
static $file_count;
|
| 30 |
static $cdn_file_count;
|
| 31 |
static $synced_files_per_server_count;
|
| 32 |
static $total_time;
|
| 33 |
static $synced_files;
|
| 34 |
static $unsynced_files;
|
| 35 |
static $drupal_root_path;
|
| 36 |
|
| 37 |
if (!isset($drupal_root_path)) {
|
| 38 |
$drupal_root_path = dirname('.');
|
| 39 |
}
|
| 40 |
|
| 41 |
if (!isset($file_count)) {
|
| 42 |
$files = array();
|
| 43 |
$file_count = 0;
|
| 44 |
$cdn_file_count = 0;
|
| 45 |
$synced_files_per_server_count = array();
|
| 46 |
$total_time = 0;
|
| 47 |
$synced_files = array();
|
| 48 |
$unsynced_files = array();
|
| 49 |
}
|
| 50 |
|
| 51 |
// If the function is called with parameters set, save the statistics. If no
|
| 52 |
// parameters are passed, return the collected statistics.
|
| 53 |
if ($file && !array_key_exists($file, $files)) {
|
| 54 |
$files[$file] = TRUE;
|
| 55 |
$file_count++;
|
| 56 |
$total_time += $time;
|
| 57 |
|
| 58 |
if ($file_cdn_url !== FALSE) {
|
| 59 |
$cdn_file_count++;
|
| 60 |
|
| 61 |
$synced_files[] = array(
|
| 62 |
'file' => $file,
|
| 63 |
'absolute path' => realpath($drupal_root_path . '/' . $file),
|
| 64 |
'cdn_url' => $file_cdn_url,
|
| 65 |
'server' => ($server === FALSE) ? '' : $server,
|
| 66 |
);
|
| 67 |
|
| 68 |
// $server is only set in advanced mode.
|
| 69 |
if ($server !== FALSE) {
|
| 70 |
if (!array_key_exists($server, $synced_files_per_server_count)) {
|
| 71 |
$synced_files_per_server_count[$server] = 0;
|
| 72 |
}
|
| 73 |
$synced_files_per_server_count[$server]++;
|
| 74 |
}
|
| 75 |
}
|
| 76 |
else {
|
| 77 |
$unsynced_files[] = $file;
|
| 78 |
}
|
| 79 |
}
|
| 80 |
elseif (!$file) {
|
| 81 |
return array(
|
| 82 |
$file_count,
|
| 83 |
$cdn_file_count,
|
| 84 |
$synced_files_per_server_count,
|
| 85 |
$total_time,
|
| 86 |
$synced_files,
|
| 87 |
$unsynced_files,
|
| 88 |
);
|
| 89 |
}
|
| 90 |
}
|