]> git.mjollnir.org Git - moodle.git/commitdiff
lib/simplepie MDL-7946 - improve simplepie defaults
authorpoltawski <poltawski>
Thu, 30 Jul 2009 18:57:19 +0000 (18:57 +0000)
committerpoltawski <poltawski>
Thu, 30 Jul 2009 18:57:19 +0000 (18:57 +0000)
- 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
lib/simplepie/moodle_simplepie.php

index 5b58da5ddd3284489eaf4e0060ead7c470762647..02d0f11c8d2aff3b183e6d5177e50c943b0173ce 100644 (file)
             @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();
index 5e5d946364dadf1c41315d93677bc810dc2dd6d2..3ea8e9580439a7a9d10f735cc2a1c09b3f0276ac 100644 (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