I was trying out this tutorial for reading rss feeds with a php file and caching it.
I copied and pasted the source into my own project. I am using XAMPP on Mac OS X installation.
Here is the source:
First of all, I cannot create a directory with mkdir. It says permission denied.
Second, $feed = file_get_contents($path, true); is not returning a php object. I mean when i check it with if ( is_object($feed) && $feed->query->count ), I cannot get through.
Last, I cannot $cachefile = fopen($cache, 'wb');
<?php
$cache = dirname(__FILE__) . "/cache/feed";
echo filemtime($cache);
if(filemtime($cache))
{
// Get from server
if ( !file_exists(dirname(__FILE__) . '/cache') ) {
mkdir(dirname(__FILE__) . '/cache', 0777);
}
// YQL query (SELECT * from feed ... ) // Split for readability
$path = "http://query.yahooapis.com/v1/public/yql?q=";
$path .= urlencode("SELECT * FROM feed WHERE url='http://feeds.hindustantimes.com/HT-HomePage-TopStories'");
$path .= "&format=json";
// Call YQL, and if the query didn't fail, cache the returned data
$feed = file_get_contents($path, true);
print_r($feed);
// If something was returned, cache
if ( is_object($feed) && $feed->query->count ) {
$cachefile = fopen($cache, 'wb');
fwrite($cachefile, $feed);
fclose($cachefile);
echo 'writing to disk';
}
}
else
{
// We already have local cache. Use that instead.
$feed = file_get_contents($cache);
}
// Decode that shizzle
$feed = json_decode($feed);
print_r($feed);
// Include the view
//include('views/site.tmpl.php');
?>
Pretty sure XAMPP runs as the “nobody” user so you’re going to have to give “nobody” permissions to the directories you want to be writable:
Keep in mind that XAMPP is a great dev server, but is not secure out of the box so be careful about using this in production. See this article for relevant issues.