1 common.inc backdrop_page_footer()

Performs end-of-request tasks.

This function sets the page cache if appropriate, and allows modules to react to the closing of the page by calling hook_exit().

File

core/includes/common.inc, line 3180
Common functions that many Backdrop modules will need to reference.

Code

function backdrop_page_footer() {
  module_invoke_all('exit');

  // Commit the user session, if needed. This must be done before sending the
  // response, as it may set a cookie header.
  backdrop_session_commit();

  // In order to do post-delivery processing (e.g. cron run), we must close the
  // connection. Otherwise the connection will wait for PHP to finish before it
  // is used again in a subsequent request, such as for a JS or CSS file.
  if (!backdrop_is_background()) {
    header('Connection: close');
  }

  // Get the contents of the output buffer, which was started in
  // _backdrop_bootstrap_page_header().
  $page_length = ob_get_length();
  $page_content = ob_get_clean();

  if (config_get('system.core', 'cache') && backdrop_page_is_cacheable()) {
    $cache = backdrop_page_create_cache($page_content);
    // If this is a background request, there is no need to print the page to a
    // buffer that will never be sent to the browser.
    if (!backdrop_is_background()) {
      backdrop_serve_page_from_cache($cache);
    }
  }
  else {
    backdrop_set_length_headers($page_length);
    // Do not print body content on HTTP HEAD requests. See
    // backdrop_serve_page_from_cache() for further explanation.
    if ($_SERVER['REQUEST_METHOD'] !== 'HEAD') {
      print $page_content;
    }
  }

  // If we're not already in a background request, flush to the browser.
  if (!backdrop_is_background() && $_SERVER['REQUEST_METHOD'] !== 'HEAD') {
    // Flushing for PHP-FPM based installations.
    if (function_exists('fastcgi_finish_request')) {
      fastcgi_finish_request();
    }
    // Flushing for LiteSpeed servers.
    elseif (function_exists('litespeed_finish_request')) {
      litespeed_finish_request();
    }
    // Flushing for Apache mod_php installations.
    else {
      flush();
    }
  }

  // Then continue background tasks without holding up the rest of the request.
  if (isset($cache)) {
    backdrop_page_save_cache($cache);
  }
  backdrop_cache_system_paths();
  module_implements_write_cache();
  system_run_automated_cron();
}