View Single Post
Old 11-08-2015, 07:18 AM  
lezinterracial
Confirmed User
 
Industry Role:
Join Date: Jul 2012
Posts: 3,064
Caching an XML file - Does this PHP cod look okay?

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);
__________________
Live Sex Shows
lezinterracial is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote