Quote:
Originally Posted by sarettah
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.
|
You are absolutely right. I don't even know why I need to call Curl at all if I am using file_put_contents like Eddie showed. But for some reason I am getting an error in SimpleXMLElement if I don't call Curl.
Here is my code now. Calling Curl on my own server is stupid, But I am getting a problem in the SimpleXMLElement function if I don't. My problem is a lack of understanding of XML. I am sure it is something simple, I just need to figure out.
Code:
$cacheName = 'chatcache.xml';
$feed_updated = filemtime('chatcache.xml');
$ageInSeconds = 120;
if(!file_exists($cacheName) || time() > $feed_updated + $ageInSeconds)
{
echo "file saved";
$contents = file_get_contents('https://chaturbate.com/affiliates/api/onlinerooms/?format=xml&wm=0CLZb');
file_put_contents($cacheName, $contents);
}
$xml_feed_url = 'http://www.bestfreecamgirls.com/chatcache.xml';
$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);
curl_close($ch);
$resource = $chat->resource;
$gender = $chat->resource->gender;
$female = "f";
$counter = 0;
if ($xml != NULL){
$chat = new SimpleXMLElement($xml);
}