summaryrefslogtreecommitdiff
path: root/modules/block.module
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2003-11-28 20:03:00 +0000
committerDries Buytaert <dries@buytaert.net>2003-11-28 20:03:00 +0000
commit733d286b8991ffa6c0b13c20255c5806913e869b (patch)
tree40b93497e8c26d4b71599f78e4025197696ddf0b /modules/block.module
parentfa5aca1ef79e318793fe9cc13befabe8b01e3b36 (diff)
downloadbrdo-733d286b8991ffa6c0b13c20255c5806913e869b.tar.gz
brdo-733d286b8991ffa6c0b13c20255c5806913e869b.tar.bz2
- Made it possible to auto-throttle blocks. That is, blocks can be
configured to be disabled when under excessive load. Patch by Jeremy.
Diffstat (limited to 'modules/block.module')
-rw-r--r--modules/block.module30
1 files changed, 22 insertions, 8 deletions
diff --git a/modules/block.module b/modules/block.module
index a6ba60145..57e4e843e 100644
--- a/modules/block.module
+++ b/modules/block.module
@@ -40,7 +40,7 @@ function block_help($section = "admin/help#block") {
$output = t("Controls the boxes that are displayed around the main content.");
break;
case 'admin/system/block':
- $output = t("Blocks are the boxes in the left- and right- side bars of the web site, depending on the choosen theme. They are created by <b>active</b> Drupal modules. In order to view a block it must be enabled. You can assign the block's placement by giving it a region and a weight. The region specifies which side of the page the block is on, and the weight sorts blocks within a region. Lighter (smaller weight value) blocks \"float up\" towards the top of the page. The path setting lets you define which pages you want a block to be shown on. The custom checkbox lets your users hide the block using their account setting. You can also create your own blocks, where you specify the content of the block rather than its being generated by a module (you can even use PHP in these). You can create one of these by clicking the %createblock link in the menu to the left. Edit and delete links will become active below for these customized blocks.", array("%createblock" => l(t("new block"), "admin/system/block/add")));
+ $output = t("Blocks are the boxes in the left- and right- side bars of the web site, depending on the choosen theme. They are created by <b>active</b> Drupal modules. In order to view a block it must be enabled. You can assign the block's placement by giving it a region and a weight. The region specifies which side of the page the block is on, and the weight sorts blocks within a region. Lighter (smaller weight value) blocks \"float up\" towards the top of the page. The path setting lets you define which pages you want a block to be shown on. The custom checkbox lets your users hide the block using their account setting. You can also create your own blocks, where you specify the content of the block rather than its being generated by a module (you can even use PHP in these). You can create one of these by clicking the %createblock link in the menu to the left. Edit and delete links will become active below for these customized blocks. Blocks can automatically be temporarily disabled to reduce server load when your site becomes extremely busy by checking auto-throttle. The auto-throttle functionality must be enabled on the %throttle.", array("%createblock" => l(t("new block"), "admin/system/block/add"), "%throttle" => l(t("throttle configuration page"), "admin/system/modules/throttle")));
break;
case 'admin/system/block/add':
$output = t("Here you can create a custom content block. Once you have created this block you must make it active, and give it a place on the page using %overview. The title is used when displaying the block. The description is used in the \"block\" column on the %overview page. If you are going to place PHP code in the block, and you have <b>create php content</b> permission (see the %permission page) you <b>must</b> change the type to PHP to make your code active.", array("%overview" => l(t("blocks"), "admin/system/block"), "%permission" => l(t("permissions"), "admin/user/permission")));
@@ -90,8 +90,8 @@ function block_block($op = "list", $delta = 0) {
function block_admin_save($edit) {
foreach ($edit as $module => $blocks) {
foreach ($blocks as $delta => $block) {
- db_query("UPDATE {blocks} SET region = %d, status = %d, custom = %d, path = '%s', weight = %d WHERE module = '%s' AND delta = '%s'",
- $block["region"], $block["status"], $block["custom"], $block["path"], $block["weight"], $module, $delta);
+ db_query("UPDATE {blocks} SET region = %d, status = %d, custom = %d, path = '%s', weight = %d, throttle = %d WHERE module = '%s' AND delta = '%s'",
+ $block["region"], $block["status"], $block["custom"], $block["path"], $block["weight"], $block["throttle"], $module, $delta);
}
}
@@ -125,6 +125,7 @@ function _block_rehash($order_by = array("weight")) {
$block["region"] = $old_blocks[$module][$delta]->region;
$block["path"] = $old_blocks[$module][$delta]->path;
$block["custom"] = $old_blocks[$module][$delta]->custom;
+ $block["throttle"] = $old_blocks[$module][$delta]->throttle;
}
else {
$block["status"] = $block["weight"] = $block["region"] = $block["custom"] = 0;
@@ -132,8 +133,8 @@ function _block_rehash($order_by = array("weight")) {
}
// reinsert blocks into table
- db_query("INSERT INTO {blocks} (module, delta, status, weight, region, path, custom) VALUES ('%s', '%s', %d, %d, %d, '%s', %d)",
- $block["module"], $block["delta"], $block["status"], $block["weight"], $block["region"], $block["path"], $block["custom"]);
+ db_query("INSERT INTO {blocks} (module, delta, status, weight, region, path, custom, throttle) VALUES ('%s', '%s', %d, %d, %d, '%s', %d, %d)",
+ $block["module"], $block["delta"], $block["status"], $block["weight"], $block["region"], $block["path"], $block["custom"], $block["throttle"]);
$blocks[] = $block;
@@ -153,7 +154,7 @@ function block_admin_display() {
$blocks = _block_rehash();
- $header = array(t("block"), t("enabled"), t("custom"), t("weight"), t("region"), t("path"), array("data" => t("operations"), "colspan" => 2));
+ $header = array(t("block"), t("enabled"), t("custom"), t("throttle"), t("weight"), t("region"), t("path"), array("data" => t("operations"), "colspan" => 2));
foreach ($blocks as $block) {
if ($block["module"] == "block") {
@@ -165,7 +166,10 @@ function block_admin_display() {
$delete = "";
}
- $rows[] = array($block["info"], array("data" => form_checkbox(NULL, $block["module"]."][".$block["delta"]."][status", 1, $block["status"]), "align" => "center"), array("data" => form_checkbox(NULL, $block["module"]."][".$block["delta"]."][custom", 1, $block["custom"]), "align" => "center"), form_weight(NULL, $block["module"]."][".$block["delta"]."][weight", $block["weight"]), form_radios(NULL, $block["module"]."][".$block["delta"]."][region", $block["region"], array(t("left"), t("right"))), form_textfield(NULL, $block["module"]."][".$block["delta"]."][path", $block["path"], 10, 255), $edit, $delete);
+ $rows[] = array($block["info"], array("data" => form_checkbox(NULL, $block["module"]."][".$block["delta"]."][status", 1, $block["status"]), "align" => "center"), array("data" => form_checkbox(NULL, $block["module"]."][".$block["delta"]."][custom", 1, $block["custom"]), "align" => "center"),
+ array("data" => form_checkbox(NULL, $block["module"]."][".$block["delta"]."][throttle", 1, $block["throttle"], NULL, variable_get("statistics_enable_auto_throttle", 0) ? NULL : array("disabled" => "disabled")), "align" => "center"),
+ form_weight(NULL, $block["module"]."][".$block["delta"]."][weight", $block["weight"]), form_radios(NULL, $block["module"]."][".$block["delta"]."][region", $block["region"], array(t("left"), t("right"))), form_textfield(NULL, $block["module"]."][".$block["delta"]."][path", $block["path"], 10, 255),
+ $edit, $delete);
}
$output = theme("table", $header, $rows);
@@ -373,7 +377,17 @@ function block_list($region) {
while ($result && ($block = db_fetch_array($result))) {
if ((($block['status'] && (!$user->uid || !$block['custom'])) || ($block['custom'] && $user->block[$block['module']][$block['delta']])) && (!$block['path'] || preg_match($block['path'], str_replace("?q=", "", request_uri())))) {
- $block = array_merge($block, module_invoke($block['module'], 'block', 'view', $block['delta']));
+
+ /*
+ ** If congestion control is enabled, check current throttle status
+ ** and see if block should be displayed based on server load.
+ */
+ if ((module_invoke("throttle", "status") < 5) && $block['throttle'] && variable_get("statistics_enable_auto_throttle", 0)) {
+ $block['content'] = t('This block has been temporarily disabled as we are currently experiencing excessive load on our webserver. The block will be automatically reenabled when the webserver is less busy.');
+ }
+ else {
+ $block = array_merge($block, module_invoke($block['module'], 'block', 'view', $block['delta']));
+ }
if ($block['content']) {
$blocks[$region]["$block[module]_$block[delta]"] = (object) $block;
}