saving rss feed into apc cache-Collection of common programming errors
i have a rss reader, i read rss-es using this line:
$content = @simplexml_load_file($feed); //$feed is the url to an rss
because this has gotten slow (i read many rss-es before serving it to the page), i want to cache it to the memory, so i changed it to the following:
if(apc_exists('feed'.$feed))
{
$content = apc_fetch('feed'.$feed);
}
else
{
$content = @simplexml_load_file($feed);
apc_store('feed'.$feed, $content, 2700+rand(0,1800));
}
the problem now is that i get an error: Uncaught exception ‘Exception’ with message ‘Serialization of ‘SimpleXMLElement’ is not allowed’
how do i achieve this? I want to have the cache in the memory, i do not want file-based cache.
EDIT: Solved with:
if(apc_exists('feed'.$feed))
{
$a = apc_fetch('feed'.$feed);
}
else
{
$a = file_get_contents($feed);
apc_store('feed'.$feed, $a, 2700+rand(0,1800));
}
$content = @simplexml_load_string($a);