PHP Classes

How to Use a PHP RSS Feed Parser That Avoids Blocking From Content Delivery Network Services That Block Robots Using the Package RSS Fetch XML: Fetch and cache an RSS or an Atom feed from a URL

Recommend this page to a friend!
     
  Info   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2026-08-08 (Yesterday) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
rssfetchxml 1.3.1MIT/X Consortium ...7.2XML, PHP 5, Web services
Description 

Author

This package can fetch and cache an RSS or Atom feed from a given URL.

It provides a class that can take a URL of an RSS feed and retrieves it using PHP's simplexml and cURL extensions, so it does not require PHP allow_url_fopen enabled to be set.

The class uses an HTTP user agent that is the same as the current user browser to avoid being blocked by content delivery network services such as CloudFlare that block robots.

The class can parse the RSS feed XML data and return a object with the RSS feed structure.

The RSS feed data can be stored in a local file in a given directory for a period of a given time length to avoid accessing the same RSS feed URL.

Innovation Award
PHP Programming Innovation award winner
July 2025
Winner
RSS feeds let Websites share content in a way if it is easy to process by other sites because they use a standard format based on XML.

Websites usually use automated scripts that act like robots that retrieve and parse RSS feeds from other sites.

The increasing number of robots that are accessing Websites lead to content delivery services to block aggressive robots.

This package provides an RSS feed retrieving class that is friendly with other Websites and can avoid blocks from content delivery services that block robots.

Manuel Lemos
Picture of Mike Jordan
  Performance   Level  
Name: Mike Jordan <contact>
Classes: 6 packages by
Country: United States United States
Innovation award
Innovation award
Nominee: 2x

Winner: 1x

Instructions

Please check this example script to learn how to retrieve, parse and cache RSS feeds of site contents.

Details

<!-- Improved compatibility of back to top link: See: https://github.com/othneildrew/Best-README-Template/pull/73 --> <a id="readme-top"></a>

<h3 align="center">rssFetchXml</h3>

<p align="center">

rssFetchXml is an RSS and Atom reader that uses PHP, Javascript and HTML to display XML feeds
<br />
<a href="https://github.com/github_username/repo_name">View Demo</a>

</p> </div>

<!-- TABLE OF CONTENTS --> <details> <summary>Table of Contents</summary> <ol>

<li>
  <a href="#about-the-project">About The Project</a>
  <ul>
    <li><a href="#built-with">Built With</a></li>
  </ul>
</li>
<li>
  <a href="#getting-started">Getting Started</a>
  <ul>
    <li><a href="#prerequisites">Prerequisites</a></li>
    <li><a href="#installation">Installation</a></li>
  </ul>
</li>
<li><a href="#usage">Usage</a></li>
<li><a href="#license">License</a></li>
<li><a href="#contact">Contact</a></li>

</ol> </details>

<!-- ABOUT THE PROJECT -->

About The Project

<b>rssFetchXml Features:</b>

  • Avoids using commercial RSS APIs that may require a subscription and fees
  • Compact code that simplifies adding an RSS feed to a webpage utilizing PHP's simplexml, cURL and Javascript.
  • Does not require allow_url_fopen enabled.
  • Using simplexml with cURL sends "friendly" RSS requests that CDNs such as Cloudflare may treat as bots with other methods.
  • Auto saves cached XML files.
  • Cache dir, cache expiration time, max number of feed links and custom error message set in config file.

<p align="right">(<a href="#readme-top">back to top</a>)</p>

Built With

<p align="right">(<a href="#readme-top">back to top</a>)</p>

<!-- GETTING STARTED -->

Getting Started

Prerequisites

  • PHP (v7.2+)
  • cURL extension enabled
  • libxml extension enabled

Installation

  1. Upload rssFetchXml.php, rss_config.php and rss_fetch.js to a directory on your server. rssFetchXml.php and rss_config.php must be in the same directory.
  2. Open `rss_config.php` and edit the following variables
    return [
     "cache_dir" => "path/to/cache/", //Path to cache dir
     "cache_expire" => 3600, //Cache expire in secs - ie: 3600 = 1 hr
     "rss_error" => "RSS fetch failed - RSS Url or feed may be unavailable", //Custom error message on feed failure
     "rss_max" => 12 //Max number of links displayed
    ];
    
  3. Open `rss_fetch.js` and edit the following variable
    let rssUrl = "https://somesite.com/rss/rssFetchXml.php";
    
  4. Add `rss_fetch.js` script link to your HTML template right before the closing `</body>` tag
    <script src="https://somesite.com/rss/rss_fetch.js"></script>
    

<p align="right">(<a href="#readme-top">back to top</a>)</p>

<!-- USAGE EXAMPLES -->

Usage

  1. Add an empty HTML div where you want to display the RSS feed. Set its class as `rss-feed` and the data attribute `data-rss` value as the RSS feed URL.
    <div class="rss-feed" data-rss="https://somesite.com/rss/feeds/feed.xml"></div>
    
  2. This will return a HTML formatted block with the following structure:
    <div class="rss-feed" data-rss="https://somesite.com/rss/feeds/feed.xml">
     <div class="rss-header"><a href="https://somesite.com/" target="_blank">Channel Title</a></div>
     <div class="rss-wrapper">
       <div class="rss-link"><a href="https://somesite.com/item.html" target="_blank">Item 1 Title</a></div>
       <div class="rss-link"><a href="https://somesite.com/item2.html" target="_blank">Item 2 Title</a></div>
       <div class="rss-link"><a href="https://somesite.com/item3.html" target="_blank">Item 3 Title</a></div>
     </div>
    </div> 
    
  3. Add the following CSS properties to your CSS file to format your feed
    .rss-feed {
     padding: .5rem;
     background-color: #fff;
     border: .063rem solid #aaa;
    }
    .rss-header {
     padding: .5rem;
    }
    .rss-header a {
     font-weight: bold;
     padding: .5rem;
     color: #000;
     text-decoration: none;
    }
    .rss-wrapper {
     height: 10rem;
     overflow-x: hidden;
     overflow-y: scroll;
     padding: .5rem;
    }
    .rss-link a {
     text-decoration: none;
    }
    

<p align="right">(<a href="#readme-top">back to top</a>)</p>

<!-- TROUBLESHOOTING -->

Troubleshooting

  1. If your are displaying the custom error message, check that the RSS feed URL is correct. Some site's CDNs may use strict security and are treating you request as a bot and returning forbidden codes. You will need to create a proxy feed from a site such as Google's <a href="https://feedburner.google.com/">Feedburner</a>.
  2. If no RSS content or error messages are being displayed, check the cache dir path you set in `rss_config` is valid and exists. Also check the URL set in `rss_fetch.js` is correct as well the script URL.

<p align="right">(<a href="#readme-top">back to top</a>)</p>

<!-- LICENSE -->

License

Distributed under the MIT license. See LICENSE.txt for more information.

<p align="right">(<a href="#readme-top">back to top</a>)</p>

<!-- CONTACT -->

Contact

Mike Jordan: mtjo62@gmail.com

Project Link: https://github.com/mtjo62/rssFetchXml

<p align="right">(<a href="#readme-top">back to top</a>)</p>


  Files folder image Files (7)  
File Role Description
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login HTML file demo.html Doc. Documentation
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation
Plain text file rssFetchXml.php Class Class source
Accessible without login Plain text file rss_config.php Aux. Configuration script
Accessible without login Plain text file rss_fetch.js Data Auxiliary data

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads  
 100%
Total:0
This week:0