I want to use Chaturbate's XML feed, But I want to save the XML file off periodically and use that instead of hitting Chaturbate's XML file every time. This code seems to work, But do you see any problems or ways to improve?
Code:
$feed_updated = filemtime('mysaved.xml');
$current_time = time();
if($current_time - $feed_updated >= 300) {
$xml_feed_url = 'https://chaturbate.com/affiliates/api/onlinerooms/?format=xml&wm=0CLZb';
$savefile = "yes";
} else {
$xml_feed_url = 'http://www.bestfreecamgirls.com/mysaved.xml';
$savefile = "no";
echo " testing - using saved";
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $xml_feed_url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_TIMEOUT,5);
$xml = curl_exec($ch);
if ($savefile == "yes"){
file_put_contents('mysaved.xml', $xml);}
curl_close($ch);