{"id":2900,"date":"2014-03-10T12:19:41","date_gmt":"2014-03-10T12:19:41","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/10\/saving-rss-feed-into-apc-cache-collection-of-common-programming-errors\/"},"modified":"2014-03-10T12:19:41","modified_gmt":"2014-03-10T12:19:41","slug":"saving-rss-feed-into-apc-cache-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/10\/saving-rss-feed-into-apc-cache-collection-of-common-programming-errors\/","title":{"rendered":"saving rss feed into apc cache-Collection of common programming errors"},"content":{"rendered":"<p>i have a rss reader, i read rss-es using this line:<\/p>\n<pre><code>$content = @simplexml_load_file($feed); \/\/$feed is the url to an rss\n<\/code><\/pre>\n<p>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:<\/p>\n<pre><code>if(apc_exists('feed'.$feed))\n{\n     $content = apc_fetch('feed'.$feed);\n}  \nelse\n{\n    $content = @simplexml_load_file($feed);\n\n        apc_store('feed'.$feed, $content, 2700+rand(0,1800));           \n}\n<\/code><\/pre>\n<p>the problem now is that i get an error: Uncaught exception &#8216;Exception&#8217; with message &#8216;Serialization of &#8216;SimpleXMLElement&#8217; is not allowed&#8217;<\/p>\n<p>how do i achieve this? I want to have the cache in the memory, i do not want file-based cache.<\/p>\n<p>EDIT: Solved with:<\/p>\n<pre><code>if(apc_exists('feed'.$feed))\n        {\n            $a = apc_fetch('feed'.$feed);\n        }  \n        else\n        {\n            $a = file_get_contents($feed);\n            apc_store('feed'.$feed, $a, 2700+rand(0,1800));         \n        }\n        $content = @simplexml_load_string($a);\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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(&#8216;feed&#8217;.$feed)) { $content = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2900","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2900","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2900"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2900\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2900"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2900"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2900"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}