WP Super Cache - Version 0.8.6

Version Description

Download this release

Release Info

Developer donncha
Plugin Icon 128x128 WP Super Cache
Version 0.8.6
Comparing to
See all releases

Code changes from version 0.8.5 to 0.8.6

Files changed (5) hide show
  1. Changelog.txt +49 -0
  2. readme.txt +8 -3
  3. wp-cache-phase1.php +4 -3
  4. wp-cache-phase2.php +24 -10
  5. wp-cache.php +10 -8
Changelog.txt CHANGED
@@ -1,3 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  2008-11-25 12:58 donncha
2
 
3
  * readme.txt, wp-cache.php: Bump version number to 0.8.5
1
+ 2008-12-04 18:12 donncha
2
+
3
+ * wp-cache-phase1.php: Added "WP-Super-Cache: WP-Cache" header for
4
+ cached php files.
5
+
6
+ 2008-12-04 17:59 donncha
7
+
8
+ * readme.txt, wp-cache.php: Bump version numberb to 2.7
9
+
10
+ 2008-12-04 17:44 donncha
11
+
12
+ * wp-cache.php: Hide unlink errors
13
+
14
+ 2008-12-04 16:53 donncha
15
+
16
+ * wp-cache-phase2.php: Use uniqid() instead of tempnam() to
17
+ generate temporary filenames.
18
+ No need for chmod.
19
+ Fixed minor typo
20
+
21
+ 2008-12-04 13:40 donncha
22
+
23
+ * wp-cache-phase2.php: Record time of cache generation
24
+
25
+ 2008-12-04 13:27 donncha
26
+
27
+ * readme.txt: Added Apache configuration docs on AllowOverride
28
+
29
+ 2008-12-02 11:00 donncha
30
+
31
+ * wp-cache.php: If WP_CACHE is not enabled, but the define() line
32
+ is in wp-config.php, stop, because it's probably commented out.
33
+
34
+ 2008-12-01 11:38 donncha
35
+
36
+ * wp-cache-phase2.php: Abort caching if plugin can't write to any
37
+ cache file, and report error
38
+ $gzsize may not survive to shutdown callback. Get the filesize
39
+ again
40
+
41
+ 2008-12-01 11:37 donncha
42
+
43
+ * wp-cache-phase1.php: Push the headers into the headers array, not
44
+ the meta object
45
+
46
+ 2008-11-25 12:58 donncha
47
+
48
+ * Changelog.txt: Updated changelog
49
+
50
  2008-11-25 12:58 donncha
51
 
52
  * readme.txt, wp-cache.php: Bump version number to 0.8.5
readme.txt CHANGED
@@ -1,8 +1,8 @@
1
  === WP Super Cache ===
2
  Contributors: donncha
3
- Tags: performance,caching,wp-cache
4
- Tested up to: 2.6.2
5
- Stable tag: 0.8.5
6
  Requires at least: 2.2
7
 
8
  A very fast caching engine for WordPress that produces static html files.
@@ -75,6 +75,11 @@ The [changelog](http://svn.wp-plugins.org/wp-super-cache/trunk/Changelog.txt) is
75
  `</IfModule>`
76
  ``
77
  `# END supercache`
 
 
 
 
 
78
 
79
  == Frequently Asked Questions ==
80
 
1
  === WP Super Cache ===
2
  Contributors: donncha
3
+ Tags: performance,caching,wp-cache,wp-super-cache
4
+ Tested up to: 2.7
5
+ Stable tag: 0.8.6
6
  Requires at least: 2.2
7
 
8
  A very fast caching engine for WordPress that produces static html files.
75
  `</IfModule>`
76
  ``
77
  `# END supercache`
78
+ 9. Apache must be configured to allow the modules above. If you receive a "500 internal error" when serving requests to anonymous users you need to dig into your Apache configuration. This configuration in my virtual host works for me:
79
+
80
+ `<Directory /home/www/>`
81
+ `AllowOverride All`
82
+ `</Directory>`
83
 
84
  == Frequently Asked Questions ==
85
 
wp-cache-phase1.php CHANGED
@@ -67,15 +67,16 @@ if( file_exists( $cache_file ) && ($mtime = @filemtime($meta_pathname)) ) {
67
  return;
68
  // Sometimes the gzip headers are lost. If this is a gzip capable client, send those headers.
69
  if( $wp_cache_gzip_encoding && !in_array( 'Content-Encoding: ' . $wp_cache_gzip_encoding, $meta->headers ) ) {
70
- array_push($meta, 'Content-Encoding: ' . $wp_cache_gzip_encoding);
71
- array_push($meta, 'Vary: Accept-Encoding, Cookie');
72
- array_push($meta, 'Content-Length: ' . filesize( $cache_file ) );
73
  }
74
  foreach ($meta->headers as $header) {
75
  // godaddy fix, via http://blog.gneu.org/2008/05/wp-supercache-on-godaddy/ and http://www.littleredrails.com/blog/2007/09/08/using-wp-cache-on-godaddy-500-error/
76
  if( strpos( $header, 'Last-Modified:' ) === false )
77
  header($header);
78
  }
 
79
  if ( !($content_size = @filesize($cache_file)) > 0 || $mtime < @filemtime($cache_file))
80
  return;
81
  if ($meta->dynamic) {
67
  return;
68
  // Sometimes the gzip headers are lost. If this is a gzip capable client, send those headers.
69
  if( $wp_cache_gzip_encoding && !in_array( 'Content-Encoding: ' . $wp_cache_gzip_encoding, $meta->headers ) ) {
70
+ array_push($meta->headers, 'Content-Encoding: ' . $wp_cache_gzip_encoding);
71
+ array_push($meta->headers, 'Vary: Accept-Encoding, Cookie');
72
+ array_push($meta->headers, 'Content-Length: ' . filesize( $cache_file ) );
73
  }
74
  foreach ($meta->headers as $header) {
75
  // godaddy fix, via http://blog.gneu.org/2008/05/wp-supercache-on-godaddy/ and http://www.littleredrails.com/blog/2007/09/08/using-wp-cache-on-godaddy-500-error/
76
  if( strpos( $header, 'Last-Modified:' ) === false )
77
  header($header);
78
  }
79
+ header( 'WP-Super-Cache: WP-Cache' );
80
  if ( !($content_size = @filesize($cache_file)) > 0 || $mtime < @filemtime($cache_file))
81
  return;
82
  if ($meta->dynamic) {
wp-cache-phase2.php CHANGED
@@ -206,7 +206,7 @@ function wp_cache_ob_callback($buffer) {
206
  if( !empty( $_GET ) || is_feed() || ( $super_cache_enabled == true && is_dir( substr( $supercachedir, 0, -1 ) . '.disabled' ) ) )
207
  $super_cache_enabled = false;
208
 
209
- $tmp_wpcache_filename = tempnam( $cache_path, "wp-cache");
210
  $fr = @fopen($tmp_wpcache_filename, 'w');
211
  if (!$fr) {
212
  $buffer .= "<!-- File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $cache_path ) . $cache_filename . " -->\n";
@@ -220,10 +220,25 @@ function wp_cache_ob_callback($buffer) {
220
  $do_cache = apply_filters( 'do_createsupercache', $user_info );
221
  if( $user_info == '' || $do_cache === true ) {
222
  $cache_fname = "{$dir}index.html";
223
- $tmp_cache_filename = tempnam( $dir, "wpsupercache");
224
  $fr2 = @fopen( $tmp_cache_filename, 'w' );
225
- if( $cache_compression )
 
 
 
 
 
 
226
  $gz = @fopen( $tmp_cache_filename . ".gz", 'w');
 
 
 
 
 
 
 
 
 
227
  }
228
  }
229
 
@@ -244,7 +259,7 @@ function wp_cache_ob_callback($buffer) {
244
  fputs($gz, gzencode( $store . '<!-- super cache gz -->', 1, FORCE_GZIP ) );
245
  } else {
246
  $buffer = apply_filters( 'wpsupercache_buffer', $buffer );
247
- $log = "<!-- Cached page served by WP-Super-Cache -->\n";
248
 
249
  if( $gz || $wp_cache_gzip_encoding ) {
250
  $gzdata = gzencode( $buffer . $log . "<!-- Compression = gzip -->", 3, FORCE_GZIP );
@@ -261,20 +276,19 @@ function wp_cache_ob_callback($buffer) {
261
  fputs($fr, $buffer.$log);
262
  }
263
  if( $fr2 )
264
- fputs($fr2, $buffer . '<!-- super cache -->' );
265
  if( $gz )
266
  fwrite($gz, $gzdata );
 
267
  }
268
  $new_cache = true;
269
  fclose($fr);
270
- @chmod( $tmp_wpcache_filename, 0666 & ~umask());
271
  if( !@rename( $tmp_wpcache_filename, $cache_path . $cache_filename ) ) {
272
  unlink( $cache_path . $cache_filename );
273
  rename( $tmp_wpcache_filename, $cache_path . $cache_filename );
274
  }
275
  if( $fr2 ) {
276
  fclose($fr2);
277
- @chmod( $tmp_cache_filename, 0666 & ~umask());
278
  if( !@rename( $tmp_cache_filename, $cache_fname ) ) {
279
  unlink( $cache_fname );
280
  rename( $tmp_cache_filename, $cache_fname );
@@ -447,13 +461,13 @@ function wp_cache_shutdown_callback() {
447
  if( $wp_cache_gzip_encoding && !in_array( 'Content-Encoding: ' . $wp_cache_gzip_encoding, $wp_cache_meta_object->headers ) ) {
448
  array_push($wp_cache_meta_object->headers, 'Content-Encoding: ' . $wp_cache_gzip_encoding);
449
  array_push($wp_cache_meta_object->headers, 'Vary: Accept-Encoding, Cookie');
450
- array_push($wp_cache_meta_object->headers, 'Content-Length: ' . $gzsize);
451
  }
452
 
453
  $serial = serialize($wp_cache_meta_object);
454
  if( !wp_cache_writers_entry() )
455
  return false;
456
- $tmp_meta_filename = tempnam( $cache_path . 'meta/', "wp-cache" );
457
  $fr = @fopen( $tmp_meta_filename, 'w');
458
  if( !$fr )
459
  @mkdir( $cache_path . 'meta' );
@@ -463,7 +477,7 @@ function wp_cache_shutdown_callback() {
463
  @chmod( $tmp_meta_filename, 0666 & ~umask());
464
  if( !@rename( $tmp_meta_filename, $cache_path . 'meta/' . $meta_file ) ) {
465
  unlink( $cache_path . 'meta/' . $meta_file );
466
- rename( $tmp_metae_filename, $cache_path . 'meta/' . $meta_file );
467
  }
468
  wp_cache_writers_exit();
469
  }
206
  if( !empty( $_GET ) || is_feed() || ( $super_cache_enabled == true && is_dir( substr( $supercachedir, 0, -1 ) . '.disabled' ) ) )
207
  $super_cache_enabled = false;
208
 
209
+ $tmp_wpcache_filename = $cache_path . uniqid( mt_rand(), true ) . '.tmp';
210
  $fr = @fopen($tmp_wpcache_filename, 'w');
211
  if (!$fr) {
212
  $buffer .= "<!-- File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $cache_path ) . $cache_filename . " -->\n";
220
  $do_cache = apply_filters( 'do_createsupercache', $user_info );
221
  if( $user_info == '' || $do_cache === true ) {
222
  $cache_fname = "{$dir}index.html";
223
+ $tmp_cache_filename = $dir . uniqid( mt_rand(), true ) . '.tmp';
224
  $fr2 = @fopen( $tmp_cache_filename, 'w' );
225
+ if (!$fr2) {
226
+ $buffer .= "<!-- File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) . " -->\n";
227
+ fclose( $fp );
228
+ unlink( $tmp_wpcache_filename );
229
+ return $buffer;
230
+ }
231
+ if( $cache_compression ) {
232
  $gz = @fopen( $tmp_cache_filename . ".gz", 'w');
233
+ if (!$gz) {
234
+ $buffer .= "<!-- File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) . ".gz -->\n";
235
+ fclose( $fp );
236
+ unlink( $tmp_wpcache_filename );
237
+ fclose( $fp2 );
238
+ unlink( $tmp_cache_filename );
239
+ return $buffer;
240
+ }
241
+ }
242
  }
243
  }
244
 
259
  fputs($gz, gzencode( $store . '<!-- super cache gz -->', 1, FORCE_GZIP ) );
260
  } else {
261
  $buffer = apply_filters( 'wpsupercache_buffer', $buffer );
262
+ $log = "<!-- Cached page generated by WP-Super-Cache on " . current_time( 'mysql' ) . " -->\n";
263
 
264
  if( $gz || $wp_cache_gzip_encoding ) {
265
  $gzdata = gzencode( $buffer . $log . "<!-- Compression = gzip -->", 3, FORCE_GZIP );
276
  fputs($fr, $buffer.$log);
277
  }
278
  if( $fr2 )
279
+ fputs($fr2, $buffer . $log . '<!-- super cache -->' );
280
  if( $gz )
281
  fwrite($gz, $gzdata );
282
+ $buffer .= $log;
283
  }
284
  $new_cache = true;
285
  fclose($fr);
 
286
  if( !@rename( $tmp_wpcache_filename, $cache_path . $cache_filename ) ) {
287
  unlink( $cache_path . $cache_filename );
288
  rename( $tmp_wpcache_filename, $cache_path . $cache_filename );
289
  }
290
  if( $fr2 ) {
291
  fclose($fr2);
 
292
  if( !@rename( $tmp_cache_filename, $cache_fname ) ) {
293
  unlink( $cache_fname );
294
  rename( $tmp_cache_filename, $cache_fname );
461
  if( $wp_cache_gzip_encoding && !in_array( 'Content-Encoding: ' . $wp_cache_gzip_encoding, $wp_cache_meta_object->headers ) ) {
462
  array_push($wp_cache_meta_object->headers, 'Content-Encoding: ' . $wp_cache_gzip_encoding);
463
  array_push($wp_cache_meta_object->headers, 'Vary: Accept-Encoding, Cookie');
464
+ array_push($wp_cache_meta_object->headers, 'Content-Length: ' . filesize( $cache_path . $cache_filename ));
465
  }
466
 
467
  $serial = serialize($wp_cache_meta_object);
468
  if( !wp_cache_writers_entry() )
469
  return false;
470
+ $tmp_meta_filename = $cache_path . 'meta/' . uniqid( mt_rand(), true ) . '.tmp';
471
  $fr = @fopen( $tmp_meta_filename, 'w');
472
  if( !$fr )
473
  @mkdir( $cache_path . 'meta' );
477
  @chmod( $tmp_meta_filename, 0666 & ~umask());
478
  if( !@rename( $tmp_meta_filename, $cache_path . 'meta/' . $meta_file ) ) {
479
  unlink( $cache_path . 'meta/' . $meta_file );
480
+ rename( $tmp_meta_filename, $cache_path . 'meta/' . $meta_file );
481
  }
482
  wp_cache_writers_exit();
483
  }
wp-cache.php CHANGED
@@ -2,8 +2,8 @@
2
  /*
3
  Plugin Name: WP Super Cache
4
  Plugin URI: http://ocaoimh.ie/wp-super-cache/
5
- Description: Very fast caching module for WordPress. Once activated, you must <a href="options-general.php?page=wpsupercache">enable the cache</a>. Based on WP-Cache by <a href="http://mnm.uib.es/gallir/">Ricardo Galli Granada</a>.
6
- Version: 0.8.5
7
  Author: Donncha O Caoimh
8
  Author URI: http://ocaoimh.ie/
9
  */
@@ -976,7 +976,7 @@ function wp_cache_check_link() {
976
  }
977
 
978
  function wp_cache_check_global_config() {
979
- if( WP_CACHE )
980
  return true;
981
 
982
  if ( file_exists( ABSPATH . 'wp-config.php') ) {
@@ -985,16 +985,18 @@ function wp_cache_check_global_config() {
985
  $global = dirname(ABSPATH) . '/wp-config.php';
986
  }
987
 
 
988
  $lines = file($global);
989
  foreach($lines as $line) {
990
  if (preg_match('/^\s*define\s*\(\s*\'WP_CACHE\'\s*,\s*(?i:TRUE|1)\s*\)\s*;/', $line)) {
991
- return true;
 
992
  }
993
  }
994
  $line = 'define(\'WP_CACHE\', true);';
995
  if (!is_writeable_ACLSafe($global) || !wp_cache_replace_line('define *\( *\'WP_CACHE\'', $line, $global) ) {
996
- echo "<b>Error: WP_CACHE is not enabled</b> in your <code>wp-config.php</code> file and I couldn't modified it.<br />";
997
- echo "Edit <code>$global</code> and add the following line: <br /><code>define('WP_CACHE', true);</code><br />Otherwise, <b>WP-Cache will not be executed</b> by Wordpress core. <br />";
998
  return false;
999
  }
1000
  return true;
@@ -1174,8 +1176,8 @@ function wp_cache_clean_cache($file_prefix) {
1174
  if ( ($handle = opendir( $cache_path )) ) {
1175
  while ( false !== ($file = readdir($handle))) {
1176
  if ( preg_match($expr, $file) ) {
1177
- unlink($cache_path . $file);
1178
- unlink($cache_path . 'meta/' . str_replace( '.html', '.term', $file ) );
1179
  }
1180
  }
1181
  closedir($handle);
2
  /*
3
  Plugin Name: WP Super Cache
4
  Plugin URI: http://ocaoimh.ie/wp-super-cache/
5
+ Description: Very fast caching module for WordPress. Once activated, you must <a href="options-general.php?page=wpsupercache">enable the cache</a>.
6
+ Version: 0.8.6
7
  Author: Donncha O Caoimh
8
  Author URI: http://ocaoimh.ie/
9
  */
976
  }
977
 
978
  function wp_cache_check_global_config() {
979
+ if( defined( 'WP_CACHE' ) )
980
  return true;
981
 
982
  if ( file_exists( ABSPATH . 'wp-config.php') ) {
985
  $global = dirname(ABSPATH) . '/wp-config.php';
986
  }
987
 
988
+ $howtoenable = "Edit <code>$global</code> and add the following line: <br /><code>define('WP_CACHE', true);</code><br />Otherwise, <b>WP-Cache will not be executed</b> by Wordpress core. <br />";
989
  $lines = file($global);
990
  foreach($lines as $line) {
991
  if (preg_match('/^\s*define\s*\(\s*\'WP_CACHE\'\s*,\s*(?i:TRUE|1)\s*\)\s*;/', $line)) {
992
+ echo $howtoenable;
993
+ return false;
994
  }
995
  }
996
  $line = 'define(\'WP_CACHE\', true);';
997
  if (!is_writeable_ACLSafe($global) || !wp_cache_replace_line('define *\( *\'WP_CACHE\'', $line, $global) ) {
998
+ echo "<b>Error: WP_CACHE is not enabled</b> in your <code>wp-config.php</code> file and I couldn't modify it.<br />";
999
+ echo $howtoenable;
1000
  return false;
1001
  }
1002
  return true;
1176
  if ( ($handle = opendir( $cache_path )) ) {
1177
  while ( false !== ($file = readdir($handle))) {
1178
  if ( preg_match($expr, $file) ) {
1179
+ @unlink($cache_path . $file);
1180
+ @unlink($cache_path . 'meta/' . str_replace( '.html', '.term', $file ) );
1181
  }
1182
  }
1183
  closedir($handle);