Using YQL to load and convert RSS feeds really, really fast.
Tuesday, December 8th, 2009 at 10:45 amMy esteemed colleague Stoyan Stefanov is currently running an advent calendar (blog post a day) on performance. Today I have a guest slot on his blog showing how you can use YQL to retrieve five RSS feeds much faster than with any other technology.
As stated at the end of the article, you could use a YQL open table with embedded JavaScript to move all of the hard conversion work to the YQL server, too.
This table does exactly that. The speed of the retrieval slows down a bit with this (as YQL needs to do another request to pull the table definition):
However, using this table to retrieve multiple feeds as HTML is dead easy:
$data = array(
‘http://code.flickr.com/blog/feed/rss/’,
‘http://feeds.delicious.com/v2/rss/codepo8?count=15’,
‘http://www.stevesouders.com/blog/feed/rss’,
‘http://www.yqlblog.net/blog/feed/’,
‘http://www.quirksmode.org/blog/index.xml’
);
$url =’http://query.yahooapis.com/v1/public/yql?q=’;
$query = “use ‘http://github.com/codepo8/yql-rss-speed-comparison/raw/master/rss.multi.list.xml’ as m;select * from m where feeds=”’”.implode(“’,’”,$data).”’” and html=’true’ and compact=’true’”;
$url.=urlencode($query).’&format=xml&diagnostics=false’;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($ch);
curl_close($ch);
$content = preg_replace(‘/.*
$content = preg_replace(‘/div>.*/’,’div>‘,$content);
echo $content;
To use the open table you simply need to give it the list of RSS feeds as the feeds parameter:
use ‘http://github.com/codepo8/yql-rss-speed-comparison/raw/master/rss.multi.list.xml’ as m;
select * from m where feeds=”
‘http://code.flickr.com/blog/feed/rss/’,
‘http://feeds.delicious.com/v2/rss/codepo8?count=15’,
‘http://www.stevesouders.com/blog/feed/rss’,
‘http://www.yqlblog.net/blog/feed/’,
‘http://www.quirksmode.org/blog/index.xml’
” and html=’true’ and compact=’true’
Try it out in the YQL console.
The html
parameter defines if you want to get HTML back from the table. Take it out to get a list of feeds instead.
See the results as HTML (with an HTML parameter) or as feeds (without the HTML parameter).
The compact
parameter defines if you want to get descriptions back for each entry or not.
See the results as HTML (without descriptions) or as HTML with descriptions.
By using the JSON-P-X output format (xml with callback) you could easily use this in JavaScript:
If you want to compare yourself, get the source code of all the examples from GitHub.
Tags: conversion, curl, loading, multicurl, open tables, performance, rss, yql
Share on Mastodon (needs instance)
Newsletter
Check out the Dev Digest Newsletter I write every week for WeAreDevelopers. Latest issues:
160: Graphs and RAGs explained and VS Code extension hacks
Graphs and RAG explained, how AI is reshaping UI and work, how to efficiently use Cursor, VS Code extensions security issues.159: AI pipelines, 10x faster TypeScript, How to interview
How to use LLMs to help you write code and how much electricity does that use? Is your API secure? 10x faster TypeScript thanks to Go!158: 🕹️ Super Mario AI 🔑 API keys in LLMs 🤙🏾 Vibe Coding
Why is AI playing Super Mario? How is hallucinating the least of our worries and what are rules for developing Safety Critical Code?157: CUDA in Python, Gemini Code Assist and back-dooring LLMs
We met with a CUDA expert from NVIDIA about the future of hardware, we look at how AI fails and how to play pong on 140 browser tabs.156: Enterprise dead, all about Bluesky and React moves on!
Learn about Bluesky as a platform, how to build a React App and how to speed up SQL. And play an impossible game in the browser.My other work:
- The Developer Advocacy Handbook
- Skillshare Classes: