2012-02-26 14 views
0

我有以下代碼可以緩存xml輸出。問題是,它將xml對象緩存到memcache中,然後訪問memcache中的xml對象,我得到錯誤:獲取節點不再存在於使用memcache的php和xml中

「警告:Memcache :: get()[memcache.get]:節點不再存在於。 ..「

$cachekey = md5($url); 

$memcache = new Memcache; 
$memcache->connect('localhost', 11211) or die ("Could not connect"); 
$data = $memcache->get($cachekey); 

if($data === FALSE) 
{ 

$data = simplexml_load_file($url); 

$memcache->set($cachekey,$data,FALSE,900) or die ("Failed to create cache set"); 

} 

我該如何解決這個問題?謝謝!

+0

我相信這是回答是:http:/ /stackoverflow.com/a/7647729/1232478 – conrad10781 2012-02-26 03:59:44

回答

0

好,我得到它的工作,而不是從我下載到一個字符串的URL加載XML文件,然後加載從字符串的xml:

$cachekey = md5($url); 

$memcache = new Memcache; 
$memcache->connect('localhost', 11211) or die ("Could not connect"); 
$data = $memcache->get($cachekey); 

if($data === FALSE) 
{ 

$data = file_get_contents($url); 

$memcache->set($cachekey,$data,FALSE,900) or die ("Failed to create cache set"); 

} 

$xmldata = simplexml_load_string($data);