View Single Post
Old 11-08-2015, 07:35 AM  
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,057
Quote:
Originally Posted by lezinterracial View Post
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);

Why do the page pull (curl) each time? You have the feed saved as mysaved.xml every 5 minutes. Just use that file as the feed in the program and don't do the curl every time.

Quote:
Code:
$feed_file='mysaved.xml';
$xml_feed_url = 'https://chaturbate.com/affiliates/api/onlinerooms/?format=xml&wm=0CLZb';
$feed_updated = filemtime('mysaved.xml');
$current_time = time();
if($current_time - $feed_updated >= 300) {
       $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);
       file_put_contents($feed_file, $xml);}
       curl_close($ch);
}
__________________
All cookies cleared!
sarettah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote