Lightning fast data retrieval with YQL

Some people at Yahoo are obsessed with performance and speed of web services. For example, Stoyan Stefanov--who took it onto himself to write a performance article a day until Christmas in his performance advent calendar. Over instant messenger we got to chatting about using YQL as a proxy to retrieve data from the web faster. When he asked me to prove it, I put together a small guest post on how to use YQL to retrieve five RSS feeds much faster than with any other technology.

The results are pretty conclusive. By taking advantage of YQL's fast connectivity to the web and all the caching magic that goes on, you can cut the retrieval time for five RSS feeds from over 4 seconds using simple cURL to 0.08 seconds using YQL:

Retrieving five RSS feeds and converting it on the server with YQL execute by  you.

The speed of YQL is one thing. Using YQL execute to not only pull the data, but also convert it server-side with JavaScript, we can consume and aggregate RSS feeds in a very simple fashion. As explained in the blog post about the multi-RSS open table you can now use YQL to get RSS back as HTML lists:

use "" as mrss;
select * from mrss where feeds="
" and html="true" and compact="true"

Try it out in the YQL console or see the XML output.

Once you've copied your URL from the console using this table is pretty easy. You can use PHP if you want to support everybody:

$url= "*%20from%20mrss%20where%20feeds%3D%22''%2C''%2C''%22%20and%20html%3D%22true%22%20and%20compact%3D%22true%22&format=xml&diagnostics=false&callback=seedfeeds";
$content = get($url);
$content = preg_replace("/.*\[\"|\"\].*/","",$content);
echo stripslashes($content);
function get($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
return $output;

And as JSON-P-X is a string inside a JSON-P object you can immediately use it in JavaScript via innerHTML.

<div id="feeds">Loading...</div>
<script type="text/javascript">
function seedfeeds(o){
var f = document.getElementById('feeds');
f.innerHTML = o.results;
<script type="text/javascript" src="*%20from%20mrss%20where%20feeds%3D%22''%2C''%2C''%22%20and%20html%3D%22true%22%20and%20compact%3D%22true%22&format=xml&diagnostics=false&callback=seedfeeds"</script>

Speed and ease of use - that's YQL for you.