【发布时间】:2011-07-12 23:14:51
【问题描述】:
尝试使用名为 get_transient 的内置 wordpress 函数缓存 xml 文件,但出现 php 错误:
unserialize() [function.unserialize]:节点不再存在
//check the db to see if it exists ( get_transient is a WordPress function)
if (false === ($response_xml = get_transient('stats_from_xml_feed'))){
$request_url = "http://example.com/feed.xml";
$request_url = urlencode($request_url);
$response_xml = @simplexml_load_file($request_url);
//kill request if connection problem
if ($response_xml === FALSE){
exit ('could not connect');
} else {
// here we throw it into the WordPress temp DB using set_transient for 12 hours
set_transient('stats_from_xml_feed', $response_xml, 60*60*12);
//some output
$res = $response_xml;
$name = $res->name;
echo $name;
}
【问题讨论】:
-
可能还有无数其他问题的重复...请在提问之前进行搜索。 tinyurl.com/4lr4nef