Skip to content
Snippets Groups Projects
Commit 59cb3c45 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- Patch #13224 by Richard Archer and Gerhard: improved gzip caching.

parent fd96728f
No related branches found
No related tags found
No related merge requests found
......@@ -380,6 +380,16 @@ function cache_clear_all($cid = NULL, $wildcard = false) {
/**
* Store the current page in the cache.
*
* We try to store a gzipped version of the cache. This requires the
* PHP zlib extension (http://php.net/manual/en/ref.zlib.php).
* Presence of the extension is checked by testing for the function
* gzencode. There are two compression algorithms: gzip and deflate.
* The majority of all modern browsers support gzip or both of them.
* We thus only deal with the gzip variant and unzip the cache in case
* the browser does not accept gzip encoding.
*
* @see drupal_page_header
*/
function page_set_cache() {
global $user, $base_url;
......@@ -387,16 +397,23 @@ function page_set_cache() {
if (!$user->uid && $_SERVER['REQUEST_METHOD'] == 'GET') {
// This will fail in some cases, see page_get_cache() for the explanation.
if ($data = ob_get_contents()) {
$cache = TRUE;
if (function_exists('gzencode')) {
if (version_compare(phpversion(), '4.2', '>=')) {
$data = gzencode($data, 9, FORCE_GZIP);
// We do not store the data in case the zlib mode is deflate.
// This should be rarely happening.
if (zlib_get_coding_type() == 'deflate') {
$cache = FALSE;
}
else {
$data = gzencode($data, FORCE_GZIP);
else if (zlib_get_coding_type() == FALSE) {
$data = gzencode($data, 9, FORCE_GZIP);
}
// The remaining case is 'gzip' which means the data is
// already compressed and nothing left to do but to store it.
}
ob_end_flush();
cache_set($base_url . request_uri(), $data, CACHE_TEMPORARY, drupal_get_headers());
if ($cache && $data) {
cache_set($base_url . request_uri(), $data, CACHE_TEMPORARY, drupal_get_headers());
}
}
}
}
......@@ -569,6 +586,8 @@ function drupal_set_title($title = NULL) {
/**
* Set HTTP headers in preparation for a page response.
*
* @see page_set_cache
*/
function drupal_page_header() {
if (variable_get('cache', 0)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment