diff --git a/admin/settings/plugins.php b/admin/settings/plugins.php index a8474ed1f76..b48e54aa033 100644 --- a/admin/settings/plugins.php +++ b/admin/settings/plugins.php @@ -197,7 +197,7 @@ if ($hassiteconfig || has_capability('moodle/question:config', $systemcontext)) $temp->add(new admin_setting_heading('managerepositories', get_string('activerepository', 'repository'), '')); $temp->add(new admin_setting_managerepository()); $temp->add(new admin_setting_heading('managerepositoriescommonheading', get_string('commonsettings', 'admin'), '')); - $temp->add(new admin_setting_configtext('repository_cache_expire', get_string('cacheexpire', 'repository'), get_string('configcacheexpire', 'repository'), 120)); + $temp->add(new admin_setting_configtext('repositorycacheexpire', get_string('cacheexpire', 'repository'), get_string('configcacheexpire', 'repository'), 120)); $ADMIN->add('repositorysettings', $temp); $ADMIN->add('repositorysettings', new admin_externalpage('repositorynew', get_string('addplugin', 'repository'), $url, 'moodle/site:config', true), diff --git a/admin/settings/server.php b/admin/settings/server.php index da5d81fbf0c..b4b124a7787 100644 --- a/admin/settings/server.php +++ b/admin/settings/server.php @@ -257,6 +257,8 @@ $temp->add(new admin_setting_configtext('rcachettl', get_string('rcachettl', 'ad 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('curlcache', get_string('curlcache', 'admin'), + get_string('configcurlcache', 'admin'), 120, PARAM_INT)); $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'), diff --git a/lang/en_utf8/admin.php b/lang/en_utf8/admin.php index d441f63e0d1..2ec37196f17 100644 --- a/lang/en_utf8/admin.php +++ b/lang/en_utf8/admin.php @@ -97,6 +97,7 @@ $string['configcourserequestnotify'] = 'Type username of user to be notified whe $string['configcourserequestnotify2'] = 'Users who will be notified when a course is requested. Only users who can approve course requests are listed here.'; $string['configcoursesperpage'] = 'Enter the number of courses to be display per page in a course listing.'; $string['configcreatornewroleid'] = 'This role is automatically assigned to creators in new courses they created. This role is not assigned if creator already has needed capabilities in parent context.'; +$string['configcurlcache'] = 'Time-to-live for cURL cache, in seconds.'; $string['configdbsessions'] = 'If enabled, this setting will use the database to store information about current sessions. This is especially useful for large/busy sites or sites built on cluster of servers. For most sites this should probably be left disabled so that the server disk is used instead. Note that changing this setting now will log out all current users (including you). If you are using MySQL please make sure that \'max_allowed_packet\' in my.cnf (or my.ini) is at least 4M.'; $string['configdebug'] = 'If you turn this on, then PHP\'s error_reporting will be increased so that more warnings are printed. This is only useful for developers.'; $string['configdebugdisplay'] = 'Set to on, the error reporting will go to the HTML page. This is practical, but breaks XHTML, JS, cookies and HTTP headers in general. Set to off, it will send the output to your server logs, allowing better debugging. The PHP setting error_log controls which log this goes to.'; @@ -304,6 +305,7 @@ $string['cronwarning'] = 'The cron.php maintenance scriptapi_key = $api_key; $this->auth_token = $auth_token; - $this->debug = $debug; + if (!empty($debug)) { + $this->debug = true; + } else { + $this->debug = false; + } } // Setup for Functions function makeRequest($method, $params = array()) { $this->_clearErrors(); - if($this->debug){ - $c = new curl(array('debug'=>true, 'cache'=>true)); - } else { - $c = new curl(array('debug'=>false, 'cache'=>true)); - } + $c = new curl(array('debug'=>$this->debug, 'cache'=>true, 'module_cache'=>'repository')); try { if ($method == 'upload'){ $request = $this->_box_api_upload_url.'/'. @@ -91,11 +91,7 @@ class boxclient { // 'password'=>'xxx')); // function getAuthToken($ticket, $username, $password) { - if($this->debug){ - $c = new curl(array('debug'=>true)); - } else { - $c = new curl(array('debug'=>false)); - } + $c = new curl(array('debug'=>$this->debug)); $c->setopt(array('CURLOPT_FOLLOWLOCATION'=>0)); $param = array( 'login_form1'=>'', @@ -133,11 +129,7 @@ class boxclient { $params['action'] = 'get_account_tree'; $params['onelevel'] = 1; $params['params[]'] = 'nozip'; - if($this->debug){ - $c = new curl(array('debug'=>true, 'cache'=>true)); - } else { - $c = new curl(array('debug'=>false, 'cache'=>true)); - } + $c = new curl(array('debug'=>$this->debug, 'cache'=>true, 'module_cache'=>'repository')); try { $args = array(); $xml = $c->get($this->_box_api_url, $params); diff --git a/lib/filelib.php b/lib/filelib.php index 0d83c786455..a3f7adf24e4 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -1626,7 +1626,11 @@ class curl { } if (!empty($options['cache'])) { if (class_exists('curl_cache')) { - $this->cache = new curl_cache; + if (!empty($options['module_cache'])) { + $this->cache = new curl_cache($options['module_cache']); + } else { + $this->cache = new curl_cache('misc'); + } } } if (!empty($CFG->proxyhost)) { @@ -2007,32 +2011,50 @@ class curl { /** * This class is used by cURL class, use case: * - * $CFG->repository_cache_expire = 120; - * $c = new curl(array('cache'=>true)); + * $CFG->repositorycacheexpire = 120; + * $CFG->curlcache = 120; + * + * $c = new curl(array('cache'=>true), 'module_cache'=>'repository'); * $ret = $c->get('http://www.google.com'); * */ class curl_cache { public $dir = ''; - function __construct(){ + /** + * + * @global $CFG + * @param string @module, which module is using curl_cache + * + */ + function __construct($module){ global $CFG; - if (!file_exists($CFG->dataroot.'/cache/repository/')) { - mkdir($CFG->dataroot.'/cache/repository/', 0777, true); + if (!empty($module)) { + $this->dir = $CFG->dataroot.'/cache/'.$module.'/'; + } else { + $this->dir = $CFG->dataroot.'/cache/misc/'; } - if(is_dir($CFG->dataroot.'/cache/repository/')) { - $this->dir = $CFG->dataroot.'/cache/repository/'; + if (!file_exists($this->dir)) { + mkdir($this->dir, 0700, true); } - if (empty($CFG->repository_cache_expire)) { - $CFG->repository_cache_expire = 120; + if ($module == 'repository') { + if (empty($CFG->repositorycacheexpire)) { + $CFG->repositorycacheexpire = 120; + } + $this->ttl = $CFG->repositorycacheexpire; + } else { + if (empty($CFG->curlcache)) { + $CFG->curlcache = 120; + } + $this->ttl = $CFG->curlcache; } } public function get($param){ global $CFG, $USER; - $this->cleanup($CFG->repository_cache_expire); + $this->cleanup($this->ttl); $filename = 'u'.$USER->id.'_'.md5(serialize($param)); if(file_exists($this->dir.$filename)) { $lasttime = filemtime($this->dir.$filename); - if(time()-$lasttime > $CFG->repository_cache_expire) + if(time()-$lasttime > $this->ttl) { return false; } else { diff --git a/lib/flickrlib.php b/lib/flickrlib.php index 8a5c623b8da..a5fc7abfa18 100755 --- a/lib/flickrlib.php +++ b/lib/flickrlib.php @@ -65,7 +65,7 @@ class phpFlickr { //Find the PHP version and store it for future reference $this->php_version = explode("-", phpversion()); $this->php_version = explode(".", $this->php_version[0]); - $this->curl = new curl(array('cache'=>true)); + $this->curl = new curl(array('cache'=>true, 'module_cache'=>'repository')); } function request ($command, $args = array()) diff --git a/repository/ws.php b/repository/ws.php index fb6f96d5428..b252ff098d9 100644 --- a/repository/ws.php +++ b/repository/ws.php @@ -76,7 +76,7 @@ break; case 'ccache': // Clean cache - $cache = new curl_cache; + $cache = new curl_cache('repository'); $cache->refresh(); $action = 'list'; break; diff --git a/repository/youtube/repository.class.php b/repository/youtube/repository.class.php index 095d9f42332..4c19813fce8 100644 --- a/repository/youtube/repository.class.php +++ b/repository/youtube/repository.class.php @@ -29,7 +29,7 @@ class repository_youtube extends repository { private function _get_collection($keyword, $start, $max, $sort) { $list = array(); $this->feed_url = 'http://gdata.youtube.com/feeds/api/videos?vq=' . urlencode($keyword) . '&format=5&start-index=' . $start . '&max-results=' .$max . '&orderby=' . $sort; - $c = new curl(array('cache'=>true)); + $c = new curl(array('cache'=>true, 'module_cache'=>'repository')); $content = $c->get($this->feed_url); $xml = simplexml_load_string($content); $media = $xml->entry->children('http://search.yahoo.com/mrss/'); diff --git a/version.php b/version.php index 9bf05077734..6dcdc805a57 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2009040600; // YYYYMMDD = date of the last version bump + $version = 2009040601; // YYYYMMDD = date of the last version bump // XX = daily increments $release = '2.0 dev (Build: 20090414)'; // Human-friendly version name