lib/simplepie MDL-7946 - improve simplepie defaults

- Specify default low connect timeout in order that 'interactive' pages are
  not slowed down by slow feeds
- Set default cache feed duration of 1 hour

In RSS feed block:
- Try really hard in cron to retreive the feed
- Set the cache duration low in order to help cron refresh the cache
This commit is contained in:
poltawski
2009-07-30 18:57:19 +00:00
parent d274f2096b
commit d175fe4c53
2 changed files with 23 additions and 3 deletions
+3
View File
@@ -304,6 +304,9 @@
@set_time_limit(60);
$feed = new moodle_simplepie();
// set timeout for longer than normal to be agressive at
// fetching feeds if possible..
$feed->set_timeout(40);
$feed->set_cache_duration(0);
$feed->set_feed_url($rec->url);
$feed->init();
+20 -3
View File
@@ -62,8 +62,21 @@ class moodle_simplepie extends SimplePie
$cachedir = moodle_simplepie::get_cache_directory();
check_dir_exists($cachedir, true, true);
parent::__construct($feedurl, $cachedir);
parent::set_output_encoding('UTF-8');
parent::__construct(null, $cachedir);
// Match moodle encoding
$this->set_output_encoding('UTF-8');
// default to a short timeout as most operations will be interactive
$this->set_timeout(2);
// 1 hour default cache
$this->set_cache_duration(3600);
// init the feed url if passed in constructor
if ($feedurl !== null) {
$this->set_feed_url($feedurl);
$this->init();
}
}
/**
@@ -111,7 +124,11 @@ class moodle_simplepie_file extends SimplePie_File
$this->method = SIMPLEPIE_FILE_SOURCE_REMOTE | SIMPLEPIE_FILE_SOURCE_CURL;
$curl = new curl();
$curl->setopt(array('CURLOPT_HEADER'=>true));
$curl->setopt( array(
'CURLOPT_HEADER' => true,
'CURLOPT_TIMEOUT' => $timeout,
'CURLOPT_CONNECTTIMEOUT' => $timeout ));
if ($headers !== null) {
// translate simplepie headers to those class curl expects