Latest SimplePie 1.2.1 and CodeIgniter 2.1.0 working together.

SimplePie is a popular RSS parser and it was always easy to integrate it with other PHP frameworks.

However, I was not able to find the latest SP (1.2.1) integrated with the latest CI (2.1.0). So I decided to upload it to GitHub and make it available for all to use. The repo is available at

https://github.com/ericbae/SimplePie_CodeIgniter

There are two things I did to make this work, which weren’t too difficult.

First is to ensure that SP references are correctly fixed up when porting to CI. This is well documented with links in

http://www.smartango.com/blog/simplepie-and-codeigniter

Secondly, when I was running this, it was giving the following error.

cURL error 6: name lookup timed out

It seemed like cURL was timing out when trying to access the remote RSS feed. The value for timeout is set to 10 seconds by default. Maybe this is a bit too strict. I changed this to 20 and it worked well.

Finally, here’s the snippet of my code to get this thing working. Make sure you include Simplepie.php in your libraries folder and also set your “cache” folder as writable.

public function aus_conf()
{
$this->load->library('Simplepie');
$this->simplepie->set_cache_location(APPPATH.'cache');
$this->simplepie->set_feed_url('http://feeds.feedburner.com/TheAustralianArt?format=xml');
$this->simplepie->init();
$this->simplepie->handle_content_type();
foreach( $this->simplepie->get_items(0, 5) as $item)
{
echo $item->get_title() . '
';
echo $item->get_description();
}
}

About Eric

ericbae.com - just a small place for me to jot down whatever I need to jot down. not much here. so don't get too disappointed. i won't.
This entry was posted in Anything & Everything. Bookmark the permalink.

2 Responses to Latest SimplePie 1.2.1 and CodeIgniter 2.1.0 working together.

  1. Darren says:

    Excellent thanks for sharing saved me a bunch of work :)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>