You are here

function imageinfo_cache_async_opp in Imageinfo Cache 6

Output text & set php in async mode.

Parameters

$output: string - Text to output to open connection.

$wait: bool - Wait 1 second?

$content_type: string - Content type header.

$length: int - Content length.

1 call to imageinfo_cache_async_opp()
imageinfo_cache_primer in ./imageinfo_cache.module
Run various theme functions so the cache is primed.

File

./imageinfo_cache.module, line 670
Cache image info for theme_imagecache & theme_imagefield_image.

Code

function imageinfo_cache_async_opp($output, $wait = TRUE, $content_type = "text/html; charset=utf-8", $length = 0) {
  if (headers_sent()) {
    return FALSE;
  }

  // Calculate Content Length
  if ($length == 0) {
    $output .= "\n";
    $length = imageinfo_cache_strlen($output) - 1;
  }

  // Prime php for background operations
  $loop = 0;
  while (ob_get_level() && $loop < 25) {
    ob_end_clean();
    $loop++;
  }
  header("Connection: close");
  ignore_user_abort();

  // Output headers & data
  ob_start();
  header("Content-type: " . $content_type);
  header("Expires: Sun, 19 Nov 1978 05:00:00 GMT");
  header("Cache-Control: no-cache");
  header("Cache-Control: must-revalidate");
  header("Content-Length: " . $length);
  header("Connection: close");
  print $output;
  ob_end_flush();
  flush();

  // wait for 1 second
  if ($wait) {
    sleep(1);
  }

  // text returned and connection closed.
  // Do background processing. Time taken after should not effect page load times.
  return TRUE;
}