I am reading an XML feed and would like to compare to an old version to check for updates. My problems at the moment are that I can't seem to make a copy of a SimpleXML object and the other problem is I'm not sure I can directly compare them. This is my code as it stands, feel free to shoot me down if it's rubbish. I'm obviously just testing on local files, but I intend to eventually load from the web. Is it okay to use sleep for very long periods? I was thinking 15 minute interval is often enough for my purpose.
error_reporting(E_NOTICE);
$file = 'tmbdata_sm.xml';
$xml_old = "";
while(true){
$xml = simplexml_load_file($file);
if($xml != $xml_old){
foreach($xml->channel->item as $item){
echo $item->title . "\n";
echo $item->link . "\n";
}
$xml_old = clone $xml;
$xml = "";
}else{
echo 'no change';
}
sleep(60);
}