Tweak for large boards, as implemented first on
Linux ForumsThis tweak eliminates the "SELECT * FROM config" query that is run on every page load.
Read and understand the entire hack before implementing it.
Here goes....
Open config.php, add the following code
at the end of the file:
- Code: Select all
$board_config_file = "/unix/path/to/your/forum/board_config.php"; // (YOU SHOULD MODIFY the ***PATH***. Filename IS board_config.php here.)
if( file_exists($board_config_file) && is_readable($board_config_file) )
{
require_once($board_config_file);
}
Save, close.
Create this new file "generate_board_config.php", it will be run as a cron job and dump the contents of your config table to a file that can be included by your forum code at runtime. You will proberly want to set this to run as an hourly cron job.
You may need to include a #!/usr/bin/php line at the top. (use "which php" to work out the correct path/file to use!).
- Code: Select all
<?
require "/unix/path/to/your/forum/config.php"; // (YOU SHOULD MODIFY the PATH. Filename is **config.php**)
$conn = mysql_connect($dbhost, $dbuser, $dbpasswd) or die("Failed to connect to database");
mysql_select_db($dbname, $conn) or die("Failed to select db");
$query = "SELECT config_name, config_value FROM config";
$res = mysql_query($query, $conn) or die(mysql_error($conn));
$contents = "<?\n";
while( $row = mysql_fetch_object($res) )
{
$config_name = $row->config_name;
$config_value = $row->config_value;
$contents .= "\$board_config['{$config_name}'] = '{$config_value}';\n";
}
$contents .= "?>";
mysql_close($conn);
if( strlen($contents) )
{
if (is_writable($board_config_file))
{
if (!$handle = fopen($board_config_file, 'w'))
{
echo "Cannot open file ($board_config_file)";
exit;
}
if (fwrite($handle, $contents) === FALSE)
{
echo "Cannot write to file ($board_config_file)";
exit;
}
fclose($handle);
}
else
{
echo "The file $board_config_file is not writable";
}
}
?>
Execute it once manually, check that board_config.php in your forum directory was created and is filled with the contents of your config table. It should look like a load of php code.
Now open common.php, Find:
- Code: Select all
$sql = "SELECT *
FROM " . CONFIG_TABLE;
if( !($result = $db->sql_query($sql)) )
{
message_die(CRITICAL_ERROR, "Could not query config information", "", __LINE__, __FILE__, $sql);
}
while ( $row = $db->sql_fetchrow($result) )
{
$board_config[$row['config_name']] = $row['config_value'];
}
Replace with:
- Code: Select all
if( count($board_config) == 0 )
{
$sql = "SELECT *
FROM " . CONFIG_TABLE;
if( !($result = $db->sql_query($sql)) )
{
message_die(CRITICAL_ERROR, "Could not query config information", "", __LINE__, __FILE__, $sql);
}
while ( $row = $db->sql_fetchrow($result) )
{
$board_config[$row['config_name']] = $row['config_value'];
}
}
This will make sure it loads the data from your config table if for any reason (eg, $board_config_file not readable / doesnt exist / is empty ) the board_config array could not be filled.
Save, close.
Done.
once your happy its working, dont forget to configure it as a cron job.
Also note, if you make a change to your board configuration on the "configuration" page of the phpbb admin panel, you will manually need to re-run this script for the changes to take effect (or wait until its triggered via cron again).
This may not deliver a great direct performance boost, but it will take load off your database server. If your database is overloaded, you will proberly appriciate this.
EG: If you have 200
page requests a minute for example, this will eliminate 200 queries on your database every minute. Over the hour (60*200) this elimimates 1200 SQL queries on your database. Ok their small queries... but queries none the less. This transfers work from your db server to your http server.
Comments, suggestions welcome, note that I offer no warrenty that it will work on your board. Also note it is beyond the scope of this post to explain to you how to use cron. Those who want to know more about cron might like to read
this tutorialhave fun

Jason