Creating a custom RSS Reader with PHP

Before you eye roll me πŸ™„ after saying PHP, hear me out.

πŸ’¬ What's your current RSS reader?

Please tell me you still use RSS πŸ™, you should, everybody should.

I used to use Feedly and there was nothing wrong with it. At least for my use:

  • Open it from time to time.
  • Get my unread items.
  • Read items.

That's it. I don't really use categories, sharing or other features.

πŸ€“ Why build my own?

First because I can and perhaps more importantly because privacy. It's a small step but now there's one less company that knows the sites I read, what I like, don't like, etc.

πŸ€·β€β™‚οΈ How do you build an RSS Reader?

First thing you do is do a Github search see if there's any open source project with proper license you can fork. Turns out there is, I took a very simply implementation and refactored it to fit my needs.

I built it with PHP and MySQL, it's easy and straightfoward. You can use many other tools that will also get the job done. I'm somewhat confortable with PHP, I remember enough of MySQL and my VPS already has both installed. So not much fricction.

Because I'm a Front-end developer I had to drop in a bunch of node packages 😁 Well, I'm using Vue for this RSS Reader.

πŸ€” What does my RSS Reader do?

  • Add feeds
  • Delete feeds
  • See unread items
  • Mark items as read (when you click the link or hit the read button)
  • Mark all items as read
  • Star items

That's it. You could have categories and other features, I don't need them. Sure I don't have "inline preview" as I would have in Feedly but I prefer to see the post in its original context. Not everybody likes that, some just want the regular pain text version. If that's what you want, this RSS Reader is not for you.

simplexml_load_file()

This function is the key of the whole thing. This allows you to read the XML feed files.

https://www.php.net/manual/en/function.simplexml-load-file.php

Then it's just a matter of querying the MySQL database to store the results.

PHP and MySQL work well together

Look at the snippet below, it queries the database to update an item's field. Not too complicated:

$mysqli->query("update ". $table_items . " set is_starred=" . $_GET['is_starred'] . " where id=" . $_GET['id']);
Code language: PHP (php)

🏎 Vue CLI + BootstrapVue

To create the Vue app I used the Vue CLI which is fantastic for this kind of projects. You don't have to think about build systems and whatnot.

Then for the components BoostrapVue is a wonderful choice to get a bunch of components plug and play, ready to use.

Fetch API

From the Vue components I simply use the Fetch API to call my PHP and query the database.

fetch(`${window.rss_reader.apiUrl}${endpoints.items}${params}`) .then(response => response.json()) .then(items => { this.items = items; this.showLoading = false; });
Code language: JavaScript (javascript)

πŸ’‘ VPS

I'm hosting this in an NGINX protected path in my VPS and I've set 2 cron jobs:

  • Fetch feeds every hour.
  • Delete feed items older than 1 week (to keep my database light).

πŸ‘¨β€πŸ’» Grab the code

https://github.com/quicoto/RSS-Reader

Leave a Reply

Add <code> Some Code </code> by using this tags.

*
*