From d175fe4c532fcbe90c5606087d8aa0a074f4217f Mon Sep 17 00:00:00 2001 From: poltawski Date: Thu, 30 Jul 2009 18:57:19 +0000 Subject: [PATCH] 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 --- blocks/rss_client/block_rss_client.php | 3 +++ lib/simplepie/moodle_simplepie.php | 23 ++++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/blocks/rss_client/block_rss_client.php b/blocks/rss_client/block_rss_client.php index 5b58da5ddd..02d0f11c8d 100644 --- a/blocks/rss_client/block_rss_client.php +++ b/blocks/rss_client/block_rss_client.php @@ -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(); diff --git a/lib/simplepie/moodle_simplepie.php b/lib/simplepie/moodle_simplepie.php index 5e5d946364..3ea8e95804 100644 --- a/lib/simplepie/moodle_simplepie.php +++ b/lib/simplepie/moodle_simplepie.php @@ -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 -- 2.39.5