Fork me on GitHub
Subscribe 1

Ticket #80 (fixed bug)

FluxBB's cache is not updated when used with apc.stat=0

  • Created: 2010-07-30 14:20:26
  • Reported by: Pierre
  • Assigned to: Reines
  • Milestone: 1.4.2
  • Component: caching
  • Priority: normal

On heavy loaded sites one might want to set apc.stat=0 which makes aPC to not stat every php file on every request but just loads the cached code from memory.

However because FluxBB stores it's cached data into plain php files any change to those wont get noticed until php/webserver is restarted.

The solution is to remove those files from apc cache if they change. Here is a working patch:

From ef2d5790132f091edd4a2e18992daf56ccb81a8f Mon Sep 17 00:00:00 2001
From: Pierre Schmitz <pierre@archlinux.de>
Date: Fri, 30 Jul 2010 16:14:06 +0200
Subject: [PATCH] Invalidate APC cache if cache files are changed

FluxBB caches some data in php files it writes into the cache directory. APC wont
check if those files were changed when apc.stat is disabled. We need to manually
remove those "cache" php files from APC's opcode cache.

Signed-off-by: Pierre Schmitz <pierre@archlinux.de>
---
 include/cache.php |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/include/cache.php b/include/cache.php
index 55d0e96..b1077a4 100644
--- a/include/cache.php
+++ b/include/cache.php
@@ -31,6 +31,9 @@ function generate_config_cache()
     fwrite($fh, '<?php'."\n\n".'define(\'PUN_CONFIG_LOADED\', 1);'."\n\n".'$pun_config = '.var_export($output, true).';'."\n\n".'?>');
 
     fclose($fh);
+
+    if (function_exists('apc_delete_file'))
+        apc_delete_file(FORUM_CACHE_DIR.'cache_config.php');
 }
 
 
@@ -56,6 +59,9 @@ function generate_bans_cache()
     fwrite($fh, '<?php'."\n\n".'define(\'PUN_BANS_LOADED\', 1);'."\n\n".'$pun_bans = '.var_export($output, true).';'."\n\n".'?>');
 
     fclose($fh);
+
+    if (function_exists('apc_delete_file'))
+        apc_delete_file(FORUM_CACHE_DIR.'cache_bans.php');
 }
 
 
@@ -81,6 +87,9 @@ function generate_ranks_cache()
     fwrite($fh, '<?php'."\n\n".'define(\'PUN_RANKS_LOADED\', 1);'."\n\n".'$pun_ranks = '.var_export($output, true).';'."\n\n".'?>');
 
     fclose($fh);
+
+    if (function_exists('apc_delete_file'))
+        apc_delete_file(FORUM_CACHE_DIR.'cache_ranks.php');
 }
 
 
@@ -139,6 +148,9 @@ function generate_quickjump_cache($group_id = false)
         fwrite($fh, $output);
 
         fclose($fh);
+
+        if (function_exists('apc_delete_file'))
+            apc_delete_file(FORUM_CACHE_DIR.'cache_quickjump_'.$group_id.'.php');
     }
 }
 
-- 
1.7.2.1

In the long run you might want to abstract read and write to the cache in order to easily provide support for APC's in memory cache, memcached or others.

History

Pierre 2010-07-30 14:45:28

  • Description changed. (Diff)

Reines 2010-07-30 15:00:25

  • Owner set to Reines.

Reines 2010-07-31 00:14:53

  • Milestone set to 1.4.2.

I've applied the patch but unfortunately Gitorious is down at the moment so I cannot push it... Will do once it's sorted, thanks for the patch.

Reines 2010-07-31 16:57:54

  • Status changed from open to fixed.

Applied in bebe0ba.

Franz 2010-08-09 22:15:44

There were one-time warnings showing up in some cases (probably only when the cache has not yet been generated and, thus, you cannot delete it). Even though they were not harmful or problematic and only occurred sometimes, I suppressed them in 8199220....