Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Rss Client Laravel Package

desarrolla2/rss-client

Deprecated RSS/Atom feed fetcher (will not be updated; migrate to FastFeed). Simple, fast RSS2.0/Atom1.0 client: add multiple feed URLs under a group name and fetch entries, with optional caching via desarrolla2/cache adapters.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation: Add the package via Composer:

    composer require desarrolla2/rss-client
    

    Note: Use dev-master if required (check Packagist).

  2. Basic Usage: Initialize the client and fetch feeds:

    use Desarrolla2\RSSClient\RSSClient;
    
    $client = new RSSClient();
    $client->addFeeds(['https://example.com/rss'], 'example_feed');
    $feeds = $client->fetch('example_feed');
    
  3. First Use Case: Display a list of headlines from a single feed in a Laravel blade template:

    // In a Laravel controller
    public function showFeed()
    {
        $client = new RSSClient();
        $client->addFeeds(['https://example.com/rss'], 'headlines');
        $feeds = $client->fetch('headlines', 5); // Limit to 5 items
        return view('feed', ['items' => $feeds]);
    }
    
    <!-- In resources/views/feed.blade.php -->
    @foreach($items as $item)
        <div>{{ $item->title }}</div>
        <small>{{ $item->pubDate }}</small>
    @endforeach
    

Implementation Patterns

Usage Patterns

  1. Grouped Feed Management: Organize feeds by logical groups (e.g., news, tech, sports) for easier maintenance:

    $client->addFeeds([
        'https://news.example.com/rss',
        'https://tech.example.com/rss'
    ], 'tech_news');
    
  2. Caching Integration: Use Laravel’s cache system by wrapping desarrolla2/cache:

    use Desarrolla2\Cache\Cache;
    use Illuminate\Support\Facades\Cache as LaravelCache;
    
    $cacheAdapter = new Cache(new LaravelCacheStore());
    $client->setCache($cacheAdapter);
    

    Note: Implement LaravelCacheStore to bridge Laravel’s cache with desarrolla2/cache.

  3. Custom Processors for Data Transformation: Extend feed data with custom logic (e.g., extract thumbnails or keywords):

    class ThumbnailProcessor implements ProcessorInterface
    {
        public function execute(NodeInterface $node, \DOMElement $item)
        {
            $thumbnail = $item->getElementsByTagName('media:thumbnail')->item(0)?->getAttribute('url');
            if ($thumbnail) {
                $node->setExtended('thumbnail', $thumbnail);
            }
        }
    }
    

    Register the processor:

    $client->pushProcessor(new ThumbnailProcessor());
    
  4. Laravel Service Provider Integration: Bind the client to Laravel’s service container for dependency injection:

    // In AppServiceProvider
    public function register()
    {
        $this->app->singleton(RSSClient::class, function ($app) {
            $client = new RSSClient();
            $client->addFeeds(config('feeds.groups'), config('feeds.cache_group'));
            return $client;
        });
    }
    

    Configure feeds in config/feeds.php:

    return [
        'groups' => [
            'news' => ['https://news.example.com/rss'],
            'tech' => ['https://tech.example.com/rss']
        ],
        'cache_group' => 'feeds'
    ];
    
  5. Queue-Based Fetching (Advanced): Offload feed fetching to a queue job to avoid blocking requests:

    // FetchFeedsJob.php
    public function handle()
    {
        $client = app(RSSClient::class);
        $feeds = $client->fetch('news');
        // Process or store feeds (e.g., save to DB)
    }
    

    Dispatch the job:

    FetchFeedsJob::dispatch();
    

Workflows

  1. Daily Feed Aggregation:

    • Schedule a Laravel command to fetch and store feeds in a database:
      // app/Console/Commands/FetchFeedsCommand.php
      public function handle()
      {
          $client = app(RSSClient::class);
          $feeds = $client->fetch('news');
          foreach ($feeds as $feed) {
              Feed::updateOrCreate(['url' => $feed->link], [
                  'title' => $feed->title,
                  'published_at' => $feed->pubDate
              ]);
          }
      }
      
    • Register the command in app/Console/Kernel.php:
      protected function schedule(Schedule $schedule)
      {
          $schedule->command('feeds:fetch')->daily();
      }
      
  2. Real-Time Updates:

    • Use Laravel Echo/Pusher to notify users of new feed items:
      // After fetching feeds, broadcast new items
      broadcast(new FeedUpdated($newItems))->toOthers();
      
  3. Feed Validation and Fallbacks:

    • Implement retry logic for failed fetches:
      try {
          $feeds = $client->fetch('news');
      } catch (\Exception $e) {
          Log::error("Feed fetch failed: " . $e->getMessage());
          // Fallback to cached data or default feed
          $feeds = Cache::get('fallback_feeds', []);
      }
      

Integration Tips

  1. Laravel Cache Adapter: Create a bridge for Laravel’s cache:

    class LaravelCacheStore implements CacheInterface
    {
        public function get($key)
        {
            return Cache::get($key);
        }
    
        public function set($key, $value, $ttl = null)
        {
            Cache::put($key, $value, $ttl);
        }
    
        // Implement other CacheInterface methods...
    }
    
  2. Database Storage: Use Eloquent to store parsed feeds:

    // Feed.php model
    protected $fillable = ['title', 'link', 'description', 'pub_date', 'source_url'];
    
  3. Testing: Mock the RSS client in tests:

    $mockClient = Mockery::mock(RSSClient::class);
    $mockClient->shouldReceive('fetch')->andReturn([$mockFeed]);
    $this->app->instance(RSSClient::class, $mockClient);
    
  4. Monitoring: Log feed fetch times and errors:

    $start = microtime(true);
    $feeds = $client->fetch('news');
    Log::info("Fetched news feed in " . (microtime(true) - $start) . " seconds");
    

Gotchas and Tips

Pitfalls

  1. Deprecation Warning:

    • The package is not maintained; plan to migrate to FastFeed in the future.
    • Tip: Document the deprecation in your project’s README or UPGRADING.md.
  2. Cache Configuration:

    • Without caching, repeated calls to fetch() will hit external APIs, slowing down your app.
    • Tip: Always configure caching in production:
      $client->setCache(new Cache(new LaravelCacheStore()));
      
  3. Feed Format Limitations:

    • Only supports RSS 2.0 and Atom 1.0. Modern feeds (e.g., JSON Feed) are unsupported.
    • Tip: Validate feed formats before integration.
  4. No Async Support:

    • Fetching feeds blocks the request thread. For high-traffic sites, use queue jobs or FastFeed’s async features.
    • Tip: Offload fetching to a queue:
      FetchFeedsJob::dispatchSync(); // For immediate results
      
  5. Custom Processor Quirks:

    • Custom processors must implement ProcessorInterface and handle NodeInterface and DOMElement.
    • Tip: Extend the base processor for reusability:
      class BaseProcessor implements ProcessorInterface
      {
          protected $sanitizer;
      
          public function __construct($sanitizer)
          {
              $this->sanitizer = $sanitizer;
          }
      
          protected function getNodeValueByTagName(\DOMElement $item, $tagName)
          {
              // Implement shared logic...
          }
      }
      
  6. Memory Usage:

    • Parsing large feeds (e.g., 1000+ items) may consume significant memory.
    • Tip: Limit items with fetch('group', 50) or stream results.
  7. SSL/TLS Issues:

    • Some feeds may fail due to SSL certificate errors.
    • Tip: Configure PHP’s curl or openssl settings or use a custom HTTP client.

Debugging

  1. Feed Fetch Failures:
    • Check for HTTP errors (e.g., 404, 500) or malformed XML:
      try {
          $feeds = $client->fetch('news');
      } catch (\Exception $e) {
          Log::
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui