--- boost.module Sat May 2 13:36:39 2009 +++ boost.module Fri May 22 17:26:13 2009 @@ -59,46 +59,40 @@ * Implementation of hook_init(). Performs page setup tasks if page not cached. */ function boost_init() { - // Stop right here unless we're being called for an ordinary page request - if (strpos($_SERVER['SCRIPT_FILENAME'], 'index.php') === FALSE || variable_get('site_offline', 0)) - return; - - // TODO: check interaction with other modules that use ob_start(); this - // may have to be moved to an earlier stage of the page request. - if (!variable_get('cache', CACHE_DISABLED) && BOOST_ENABLED) { - global $user; - $GLOBALS['_boost_path'] = (empty($_REQUEST['q'])) ? 'index' : $_REQUEST['q']; - - // For authenticated users, set a special cookie to prevent them - // inadvertently getting served pages from the static page cache. - if (!empty($user->uid)) { - boost_set_cookie($user); + // Make the proper filename for our query + $fname = ''; + foreach ($_GET as $key => $val) { + if ($key != 'q') { + $fname .= (empty($fname) ? '' : '&') . $key . '=' . $val; } - // We only serve cached pages for GET requests by anonymous visitors. - // Also pages with 'nocache' parameter in request will never be cached - else if ($_SERVER['REQUEST_METHOD'] == 'GET' && !isset($_GET['nocache'])) { - // Make the proper filename for our query - // $_GET here is okay to use - $_GET['q'] is not involved here - see != 'q' below - $fname = ''; - foreach ($_GET as $key => $val) { - if ($key != 'q') { - $fname .= (empty($fname) ? '' : '&') . $key . '=' . $val; - } - } - $fname = (empty($fname) ? '' : '_' . $fname); - - // Make sure the page is cacheable according to our current configuration: - if (boost_is_cacheable($GLOBALS['_boost_path'])) { - // In the event of errors such as drupal_not_found(), GET['q'] is - // changed before _boost_ob_handler() is called. Apache is going to - // look in the cache for the original path, however, so we need to - // preserve it. - $GLOBALS['_boost_query'] = $fname; - - ob_start('_boost_ob_handler'); - } - } } + //set variables + $GLOBALS['_boost_query'] = (empty($fname) ? '' : '_' . $fname); + $GLOBALS['_boost_path'] = (empty($_REQUEST['q'])) ? 'index' : $_REQUEST['q']; + global $user; + + // Make sure the page is/should be cached according to our current configuration + if ( strpos($_SERVER['SCRIPT_FILENAME'], 'index.php') === FALSE + || variable_get('site_offline', 0) + || $_SERVER['REQUEST_METHOD'] != 'GET' + || $_SERVER['SERVER_SOFTWARE'] === 'PHP CLI' + || variable_get('cache', CACHE_DISABLED) + || !BOOST_ENABLED + || isset($_GET['nocache']) + || !boost_is_cacheable($GLOBALS['_boost_path']) + ) { + return; + } + + // For authenticated users, set a special cookie to prevent them + // inadvertently getting served pages from the static page cache. + if (!empty($user->uid)) { + boost_set_cookie($user); + } + // We only generate cached pages for anonymous visitors. + else { + ob_start('_boost_ob_handler'); + } } /** @@ -356,13 +350,28 @@ // Ensure we're in the correct working directory, since some web servers (e.g. Apache) mess this up here. chdir(dirname($_SERVER['SCRIPT_FILENAME'])); + if ($error = error_get_last()){ + switch($error['type']){ + case E_NOTICE: //Ignore run-time notices + case E_USER_NOTICE: //Ignore user-generated notice message + case E_DEPRECATED: //Ignore run-time notices + case E_USER_DEPRECATED: //Ignore user-generated notice message + break; + default: //Do not cache page on all other errors + return $buffer; + } + } + // Check the currently set content type (at present we can't deal with // anything else than HTML) and the HTTP response code. We're going to be // exceedingly conservative here and only cache 'text/html' pages that // were output with a 200 OK status. Anything more is simply asking for // loads of trouble. - if (_boost_get_content_type() == 'text/html' && _boost_get_http_status() == 200) { - if (strlen($buffer) > 0) { // Sanity check + if ( _boost_get_http_status() == 200 + && count(drupal_get_messages(NULL, FALSE)) == 0 + && strlen($buffer) > 0 + ) { + if (_boost_get_content_type() == 'text/html') { boost_cache_set($GLOBALS['_boost_path'], $buffer); } }