diff --git a/admin/settings/server.php b/admin/settings/server.php index 24373a74170..8993484f3a5 100644 --- a/admin/settings/server.php +++ b/admin/settings/server.php @@ -175,7 +175,27 @@ $ADMIN->add('server', new admin_externalpage('phpinfo', get_string('phpinfo'), " // "performance" settingpage $temp = new admin_settingpage('performance', get_string('performance', 'admin')); -$temp->add(new admin_setting_configtext('enablerecordcache', get_string('enablerecordcache', 'admin'), get_string('configenablerecordcache', 'admin'), 50)); +$temp->add(new admin_setting_configselect('cachetype', get_string('cachetype', 'admin'), + get_string('configcachetype', 'admin'), false, + array( '' => 'none', + 'internal' => 'internal', + 'memcached' => 'memcached', + 'eaccelerator' => 'eaccelerator'))); +// NOTE: $CFG->rcache is forced to bool in lib/setup.php +$temp->add(new admin_setting_configselect('rcache', get_string('rcache', 'admin'), + get_string('configrcache', 'admin'), false, + array( '0' => 'false', + '1' => 'true'))); +$temp->add(new admin_setting_configtext('rcachettl', get_string('rcachettl', 'admin'), + get_string('configrcachettl', 'admin'), 10)); +$temp->add(new admin_setting_configtext('intcachemax', get_string('intcachemax', 'admin'), + get_string('configintcachemax', 'admin'), 10)); +$temp->add(new admin_setting_configtext('memcachedhosts', get_string('memcachedhosts', 'admin'), + get_string('configmemcachedhosts', 'admin'), '')); +$temp->add(new admin_setting_configselect('memcachedpconn', get_string('memcachedpconn', 'admin'), + get_string('configmemcachedpconn', 'admin'), false, + array( '0' => 'false', + '1' => 'true'))); $ADMIN->add('server', $temp); if (file_exists("$CFG->dirroot/$CFG->admin/mysql/frame.php")) { diff --git a/lang/en_utf8/admin.php b/lang/en_utf8/admin.php index 25f8855f8e3..63019013161 100644 --- a/lang/en_utf8/admin.php +++ b/lang/en_utf8/admin.php @@ -34,6 +34,7 @@ $string['bookmarkalreadyexists'] = 'You have already bookmarked this page.'; $string['bookmarkdeleted'] = 'Bookmark deleted.'; $string['bookmarkthispage'] = 'bookmark this page'; $string['cachetext'] = 'Text cache lifetime'; +$string['cachetype'] = 'Cache Type'; $string['calendar_weekend'] = 'Weekend Days'; $string['calendarsettings'] = 'Calendar'; $string['change'] = 'change'; @@ -58,6 +59,7 @@ $string['configauthenticationplugins'] = 'Please choose the authentication plugi $string['configautologinguests'] = 'Should visitors be logged in as guests automatically when entering courses with guest access?'; $string['configbloglevel'] = 'This setting allows you to restrict the level to which user blogs can be viewed on this site. Note that they specify the maximum context of the VIEWER not the poster or the types of blog posts. Blogs can also be disabled completely if you don\'t want them at all.'; $string['configcachetext'] = 'For larger sites or sites that use text filters, this setting can really speed things up. Copies of texts will be retained in their processed form for the time specified here. Setting this too small may actually slow things down slightly, but setting it too large may mean texts take too long to refresh (with new links, for example).'; +$string['configcachetype'] = 'Select a type of cache for Moodle to use. This will only configure the cache, remember to enable rcache so that the cache is used for something. Use only if you need to reduce the load on the database system -- otherwise Moodle will actually run slower. Medium-traffic sites may see benefits using \'internal\'. A single webserver with eAccelerator or Turckmmcache installed with the shared memory options enabled should try \'eaccelerator\'. If you have a multiple-server setup, and you have one or more memcached daemons running and the PHP-memcached extension, select \'memcached\' and configure the memached options below.
Note: make sure you test performance under load and tune accordingly -- the caches can make your site slower. In high-traffic situations, eAccelerator and memcached can yield the most benefits, but have the higher costs in CPU usage on the webserver.'; $string['configclamactlikevirus'] = 'Treat files like viruses'; $string['configclamdonothing'] = 'Treat files as OK'; $string['configclamfailureonupload'] = 'If you have configured clam to scan uploaded files, but it is configured incorrectly or fails to run for some unknown reason, how should it behave? If you choose \'Treat files like viruses\', they\'ll be moved into the quarantine area, or deleted. If you choose \'Treat files as OK\', the files will be moved to the desination directory like normal. Either way, admins will be alerted that clam has failed. If you choose \'Treat files like viruses\' and for some reason clam fails to run (usually because you have entered an invalid pathtoclam), ALL files that are uploaded will be moved to the given quarantine area, or deleted. Be careful with this setting.'; @@ -82,7 +84,6 @@ $string['configeditorfontlist'] = 'Select the fonts that should appear in the ed $string['configenableajax'] = 'This setting allows you to control the use of AJAX (advanced client/server interfaces using Javascript) across the whole site. With this setting enabled users can sill make a choice in their profile, otherwise AJAX is disabled for everybody.'; $string['configenablecourserequests'] = 'This will allow any user to request a course be created.'; $string['configenableglobalsearch'] = 'This setting enables global text searching in resources and activities, it is not compatible with PHP 4.'; -$string['configenablerecordcache'] = 'If you set this to a number higher than 0, some in-memory caching will be performed while retrieving info from the database. This means that your database throughput will be better but, on the other hand, your web server memory requirements will be slightly increased. Generally we recommend values of around 50 unless your server is low on memory. Some processes may choose to override this setting where the developer is certain of a performance increase.'; $string['configenablerssfeeds'] = 'This switch will enable RSS feeds from across the site. To actually see any change you will need to enable RSS feeds in the individual modules too - go to the Modules settings under Admin Configuration.'; $string['configenablerssfeedsdisabled'] = 'It is not available because RSS feeds are disabled in all the Site. To enable them, go to the Variables settings under Admin Configuration.'; $string['configenablestats'] = 'If you choose \'yes\' here, Moodle\'s cronjob will process the logs and gather some statistics. Depending on the amount of traffic on your site, this can take awhile. If you enable this, you will be able to see some interesting graphs and statistics about each of your courses, or on a sitewide basis.'; @@ -105,6 +106,7 @@ $string['configgradebookroles'] = 'This setting allows you to control who appear $string['confighiddenuserfields'] = 'Select which user infomation fields you wish to hide from other users other than course teachers/admins. This will increase student privacy. Hold CTRL key to select multiple fields.'; $string['confightmleditor'] = 'Choose whether or not to allow use of the embedded HTML text editor. Even if you choose allow, this editor will only appear when the user is using a compatible web browser. Users can also choose not to use it.'; $string['configidnumber'] = 'This option specifies whether (a) Users are not be asked for an ID number at all, (b) Users are asked for an ID number but can leave it blank or (c) Users are asked for an ID Number and cannot leave it blank. If given the User\'s ID number is displayed in their Profile.'; +$string['configintcachemax'] = 'For internal cache only. Maximum number of records to keep in the cache. Recommended value: 50. Use lower values to reduce memory usage.'; $string['configintro'] = 'On this page you can specify a number of configuration variables that help make Moodle work properly on your server. Don\'t worry too much about it - the defaults will usually work fine and you can always come back to this page later and change these settings.'; $string['configintroadmin'] = 'On this page you should configure your main administrator account which will have complete control over the site. Make sure you give it a secure username and password as well as a valid email address. You can create more admin accounts later on.'; $string['configintrosite'] = 'This page allows you to configure the front page and name of this new site. You can come back here later to change these settings any time using the Administration menus.'; @@ -123,6 +125,8 @@ $string['configlookahead'] = 'Days to Lookahead'; $string['configmaxbytes'] = 'This specifies a maximum size that uploaded files can be throughout the whole site. This setting is limited by the PHP settings post_max_size and upload_max_filesize, as well as the Apache setting LimitRequestBody. In turn, maxbytes limits the range of sizes that can be chosen at course level or module level.'; $string['configmaxeditingtime'] = 'This specifies the amount of time people have to re-edit forum postings, glossary comments etc. Usually 30 minutes is a good value.'; $string['configmaxevents'] = 'Events to Lookahead'; +$string['configmemcachedhosts'] = 'For memcached. Comma-separated list of hosts that are running the memcached daemon. Use IP addresses to avoid DNS latency. memcached does not behave well if you add/remove hosts on a running setup.'; +$string['configmemcachedpconn'] = 'For memcached. Use persistent connections. Use carefully -- it can make Apache/PHP crash after a restart of the memcached daemon.'; $string['configmessaging'] = 'Should the messaging system between site users be enabled?'; $string['configmymoodleredirect'] = 'This setting forces redirects to /my on login for non-admins and replaces the top level site breadcrumb with /my'; $string['confignonmetacoursesyncroleids'] = 'By default all enrolments from child courses are synchronised to metacourses. Roles that are selected here will not be included in the synchronisation process.'; @@ -142,6 +146,8 @@ $string['configcronclionly'] = 'If this is set, then the cron script can only be $string['configcronremotepassword'] = 'This means that the cron.php script cannot be run from a web browser without supplying the password using the following form of URL:
     http://site.example.com/admin.cron.php?password=opensesame
 
If this is left empty, no password is required.'; +$string['configrcache'] = 'Use the cache to store database records. Remember to set \'cachetype\' as well!'; +$string['configrcachettl'] = 'Time-to-live for cached records, in seconds. Use a short (<15) value here.'; $string['configrequestedstudentname'] = 'Word for student used in requested courses'; $string['configrequestedstudentsname'] = 'Word for students used in requested courses'; $string['configrequestedteachername'] = 'Word for teacher used in requested courses'; @@ -301,6 +307,7 @@ $string['includemoduleuserdata'] = 'Include module user data'; $string['incompatibleblocks'] = 'Incompatible blocks'; $string['install'] = 'Install selected language pack'; $string['installedlangs'] = 'Installed language packs'; +$string['intcachemax'] = 'Int. cache max'; $string['invalidsection'] = 'Invalid section.'; $string['invaliduserchangeme'] = 'Username \"changeme\" is reserved -- you cannot create an account with it.'; $string['iplookup'] = 'IP address lookup'; @@ -345,6 +352,8 @@ $string['mediapluginrpm'] = 'Enable .rpm filter'; $string['mediapluginswf'] = 'Enable .swf filter'; $string['mediapluginswfnote'] = 'As a default security measure, normal users should not allowed to embed swf flash files.'; $string['mediapluginwmv'] = 'Enable .wmv filter'; +$string['memcachedhosts'] = 'memcached hosts'; +$string['memcachedpconn'] = 'memcached use persistent connections'; $string['messaging'] = 'Enable messaging system'; $string['misc'] = 'Miscellaneous'; $string['modulesecurity'] = 'Module security'; @@ -438,6 +447,8 @@ $string['protectusernames'] = 'Protect usernames'; $string['proxyhost'] = 'Proxy host'; $string['proxyport'] = 'Proxy port'; $string['quarantinedir'] = 'Quarantine directory'; +$string['rcache'] = 'Record cache'; +$string['rcachettl'] = 'Record cache TTL'; $string['releasenoteslink'] = 'For information about this version of Moodle, please see the online Release Notes'; $string['remotelangnotavailable'] = 'Because Moodle can not connect to download.moodle.org, we are unable to do language pack installation automatically. Please download the appropriate zip file(s) from the list below, copy them to your $a directory and unzip them manually.'; $string['renameerrors'] = 'Errors in renames'; diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 4317deab5bc..f5c15e9bc3b 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -510,6 +510,20 @@ function xmldb_main_upgrade($oldversion=0) { /// use get record set to iterate slower build_context_rel(); } + + if ($result && $oldversion < 2007011501) { + if (!empty($CFG->enablerecordcache) && empty($CFG->rcache) && + // Note: won't force-load these settings into CFG + // we don't need or want cache during the upgrade itself + empty($CFG->cachetype) && empty($CFG->intcachemax)) { + set_config('cachetype', 'internal'); + set_config('rcache', true); + set_config('intcachemax', $CFG->enablerecordcache); + unset_config('enablerecordcache'); + unset($CFG->enablerecordcache); + } + } + return $result; } diff --git a/lib/dmllib.php b/lib/dmllib.php index 38ae9ba47d1..17a206d7b51 100644 --- a/lib/dmllib.php +++ b/lib/dmllib.php @@ -386,7 +386,7 @@ function get_record($table, $field1, $value1, $field2='', $value2='', $field3='' // Check to see whether this record is eligible for caching (fields=*, only condition is id) $docache = false; - if (!empty($CFG->rcache) && $field1=='id' && !$field2 && !$field3 && $fields=='*') { + if ($CFG->rcache === true && $field1=='id' && !$field2 && !$field3 && $fields=='*') { $docache = true; // If it's in the cache, return it $cached = rcache_getforfill($table, $value1); @@ -1044,7 +1044,7 @@ function set_field($table, $newfield, $newvalue, $field1, $value1, $field2='', $ // Clear record_cache based on the parameters passed // (individual record or whole table) - if (!empty($CFG->rcache)) { + if ($CFG->rcache === true) { if ($field1 == 'id') { rcache_unset($table, $value1); } else if ($field2 == 'id') { @@ -1086,7 +1086,7 @@ function set_field_select($table, $newfield, $newvalue, $select, $localcall = fa // Clear record_cache based on the parameters passed // (individual record or whole table) - if (!empty($CFG->rcache)) { + if ($CFG->rcache === true) { rcache_unset_table($table); } } @@ -1145,7 +1145,7 @@ function delete_records($table, $field1='', $value1='', $field2='', $value2='', // Clear record_cache based on the parameters passed // (individual record or whole table) - if (!empty($CFG->rcache)) { + if ($CFG->rcache === true) { if ($field1 == 'id') { rcache_unset($table, $value1); } else if ($field2 == 'id') { @@ -1179,7 +1179,7 @@ function delete_records_select($table, $select='') { global $CFG, $db; // Clear record_cache (whole table) - if (!empty($CFG->rcache)) { + if ($CFG->rcache === true) { rcache_unset_table($table); } @@ -1393,7 +1393,7 @@ function update_record($table, $dataobject) { } // Remove this record from record cache since it will change - if (!empty($CFG->rcache)) { + if ($CFG->rcache === true) { rcache_unset($table, $dataobject->id); } @@ -2080,7 +2080,7 @@ function db_update_lobs ($table, $sqlcondition, &$clobs, &$blobs) { function rcache_set($table, $id, $rec) { global $CFG, $MCACHE, $rcache; - if ($CFG->rcache === 'internal') { + if ($CFG->cachetype === 'internal') { $rcache->data[$table][$id] = $rec; } else { $key = $table . '|' . $id; @@ -2112,7 +2112,7 @@ function rcache_set($table, $id, $rec) { function rcache_unset($table, $id) { global $CFG, $MCACHE, $rcache; - if ($CFG->rcache === 'internal') { + if ($CFG->cachetype === 'internal') { if (isset($rcache->data[$table][$id])) { unset($rcache->data[$table][$id]); } @@ -2142,7 +2142,7 @@ function rcache_unset($table, $id) { function rcache_get($table, $id) { global $CFG, $MCACHE, $rcache; - if ($CFG->rcache === 'internal') { + if ($CFG->cachetype === 'internal') { if (isset($rcache->data[$table][$id])) { $rcache->hits++; return $rcache->data[$table][$id]; @@ -2197,7 +2197,7 @@ function rcache_get($table, $id) { function rcache_getforfill($table, $id) { global $CFG, $MCACHE, $rcache; - if ($CFG->rcache === 'internal') { + if ($CFG->cachetype === 'internal') { return rcache_get($table, $id); } @@ -2254,7 +2254,7 @@ function rcache_releaseforfill($table, $id) { function rcache_unset_table ($table) { global $CFG, $MCACHE, $rcache; - if ($CFG->rcache === 'internal') { + if ($CFG->cachetype === 'internal') { if (isset($rcache->data[$table])) { unset($rcache->data[$table]); } diff --git a/lib/setup.php b/lib/setup.php index 01de893e7c3..43e294ce20a 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -207,6 +207,7 @@ global $HTTPSPAGEREQUIRED; configure_dbconnection(); /// Load up any configuration from the config table + $CFG->rcache = false; $CFG = get_config(); /// Turn on SQL logging if required @@ -267,11 +268,25 @@ global $HTTPSPAGEREQUIRED; /// Shared-Memory cache init -- will set $MCACHE /// $MCACHE is a global object that offers at least add(), set() and delete() /// with similar semantics to the memcached PHP API http://php.net/memcache - if (!empty($CFG->memcached) && !empty($CFG->memcachedhosts)) { - init_memcached(); + if (!empty($CFG->cachetype)) { + if ($CFG->cachetype === 'memcached' && !empty($CFG->memcachedhosts)) { + if (!init_memcached()) { + debugging("Error initialising memcached"); + } + } elseif ($CFG->cachetype === 'eaccelerator') { + if (!init_eaccelerator()) { + debugging("Error initialising eaccelerator cache"); + } + } + } else { // just make sure it is defined + $CFG->cachetype = ''; } - if (!empty($CFG->eaccelerator)) { - init_eaccelerator(); +/// Ensure we define rcache - so we can later check for it +/// with a really fast and unambiguous $CFG->rcache === false + if (empty($CFG->rcache)) { + $CFG->rcache = false; + } else { + $CFG->rcache = true; } /// Set a default enrolment configuration (see bug 1598)