summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2005-10-09 21:51:43 +0000
committerDries Buytaert <dries@buytaert.net>2005-10-09 21:51:43 +0000
commit59cb3c4568f7e8e665303041bae1aa617eeacd6e (patch)
tree647c23fd56afbf336066a98cc1dbbd6df8821e8d
parentfd96728f3ca312214c4e2ff58649a8ae338b1754 (diff)
downloadbrdo-59cb3c4568f7e8e665303041bae1aa617eeacd6e.tar.gz
brdo-59cb3c4568f7e8e665303041bae1aa617eeacd6e.tar.bz2
- Patch #13224 by Richard Archer and Gerhard: improved gzip caching.
-rw-r--r--includes/bootstrap.inc29
1 files changed, 24 insertions, 5 deletions
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc
index d597a0530..02618277f 100644
--- a/includes/bootstrap.inc
+++ b/includes/bootstrap.inc
@@ -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)) {