You are here

function _views_autorefresh_ping_pong in Views Auto-Refresh 7

2 calls to _views_autorefresh_ping_pong()
_views_autorefresh_ping_connect_db in ./views_autorefresh_ping.default.php
_views_autorefresh_ping_init in includes/views_autorefresh.inc

File

includes/views_autorefresh.inc, line 35
Views Auto-Refresh ping script global functions.

Code

function _views_autorefresh_ping_pong($pong, $timestamp_updated, $timestamp_request, $message = '', $cache = 'skip', $debug = FALSE) {
  $response = array(
    'pong' => $pong,
  );
  header('Content-Type: application/json');
  switch ($cache) {
    case 'skip':

      // Leave empty.
      break;
    case 'none':

      // HTTP headers to prevent caching the result of this call.
      header('Cache-Control: no-cache, must-revalidate');

      // HTTP/1.1.
      header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');

      // Date in the past.
      break;
    default:

      // Validate seconds.
      if (is_numeric($cache)) {
        header('Cache-Control: max-age=' . $cache);
      }
  }

  // Optionally debug.
  if ($debug) {
    $response['timestamp_updated'] = $timestamp_updated;
    $response['timestamp_request'] = $timestamp_request;
    $response['timestamp_diff'] = $timestamp_updated - $timestamp_request;
    $response['cache'] = $cache;
    $response['message'] = $message;
  }

  // JSON response.
  print json_encode($response);

  // End all other processes.
  exit;
}