Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar Mark Forums Read
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 11-08-2015, 07:18 AM   #1
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
Old 11-08-2015, 07:26 AM   #2
EddyTheDog
Just Doing My Own Thing
 
EddyTheDog's Avatar
 
Industry Role:
Join Date: Jan 2011
Location: London, Spain, New Zealand, GFY - Not Croydon...
Posts: 25,038
I posted something similar a while ago - I will see if I can find it...
__________________
-

Chaturbate Script - https://gfy.com/fucking-around-and-b...er-issues.html - Now supports White Labels
EddyTheDog is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-08-2015, 07:29 AM   #3
EddyTheDog
Just Doing My Own Thing
 
EddyTheDog's Avatar
 
Industry Role:
Join Date: Jan 2011
Location: London, Spain, New Zealand, GFY - Not Croydon...
Posts: 25,038
This was my solution:

Code:
<?php 

$cacheName = 'chatcache.xml'; 

$ageInSeconds = 60; 
  
if(!file_exists($cacheName) || filemtime($cacheName) > time() + $ageInSeconds);  
{ 
  $contents = file_get_contents('http://chaturbate.com/affiliates/api/onlinerooms/?format=xml&wm=isCir'); 
  file_put_contents($cacheName, $contents); 
} 

?>
__________________
-

Chaturbate Script - https://gfy.com/fucking-around-and-b...er-issues.html - Now supports White Labels
EddyTheDog is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-08-2015, 07:35 AM   #4
lezinterracial
Confirmed User
 
Industry Role:
Join Date: Jul 2012
Posts: 3,064

Quote:
Originally Posted by EddyTheDog View Post
This was my solution:

Code:
<?php 

$cacheName = 'chatcache.xml'; 

$ageInSeconds = 60; 
  
if(!file_exists($cacheName) || filemtime($cacheName) > time() + $ageInSeconds);  
{ 
  $contents = file_get_contents('http://chaturbate.com/affiliates/api/onlinerooms/?format=xml&wm=isCir'); 
  file_put_contents($cacheName, $contents); 
} 

?>
I like that much better. The file_exists is needed or I end up defaulting to the iframe on my landing page.

I was using Iframe's showing the top room, but I am targeting heteros, And those Voyeur_Boys are getting popular.
__________________
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
Old 11-08-2015, 07:35 AM   #5
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
Old 11-08-2015, 08:08 AM   #6
PornDiscounts-V
Confirmed User
 
PornDiscounts-V's Avatar
 
Industry Role:
Join Date: Oct 2003
Location: L.A.
Posts: 5,740
Why not save it to MySQL? Use cron job every 15 minutes.
__________________
Blog Posts - Contextual Links - Hardlinks on 600+ Blog Network
* Handwritten * 180 C Class IPs * Permanent! * Many Niches! * Bulk Discounts! GFYPosts /at/ J2Media.net
PornDiscounts-V is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-08-2015, 09:10 AM   #7
lezinterracial
Confirmed User
 
Industry Role:
Join Date: Jul 2012
Posts: 3,064
Quote:
Originally Posted by sarettah View Post
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);
}
__________________
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
Old 11-08-2015, 09:39 AM   #8
lezinterracial
Confirmed User
 
Industry Role:
Join Date: Jul 2012
Posts: 3,064
Thanks all.

Nevermind. Got it. Curl completely pulled. Had to load the file into xml this way instead of simplexmlelement used simplexml_load_file.

Although, I may switch to using curl for the copy instead of file_put_contents, So I can set a timeout if there is an issue with Chaturbate's XML file.

Code:
if (file_exists($cacheName)) {
    $chat = simplexml_load_file($cacheName);
} else {
    exit('Failed to open test.xml.');
}
__________________
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
Old 11-08-2015, 09:59 AM   #9
lezinterracial
Confirmed User
 
Industry Role:
Join Date: Jul 2012
Posts: 3,064
Quote:
Originally Posted by vvvvv View Post
Why not save it to MySQL? Use cron job every 15 minutes.
I like that idea too. That way the user doesn't have to wait if the file needs to be updated.
__________________
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
Old 11-08-2015, 10:28 AM   #10
EddyTheDog
Just Doing My Own Thing
 
EddyTheDog's Avatar
 
Industry Role:
Join Date: Jan 2011
Location: London, Spain, New Zealand, GFY - Not Croydon...
Posts: 25,038
Quote:
Originally Posted by lezinterracial View Post
I like that idea too. That way the user doesn't have to wait if the file needs to be updated.
The code I posted should be used in a cron as well - The user would never have wait for an update...

However.....

You have got me back into this project and I am looking at using a DB so you can build up the database with all the cammers in it - Then mark them as on or off line using the XML file - That way you can build your own 'Cam Offline' and profile pages with the data...

As you collect more data you can create more complex pages with lots of info for the SEs.....

NEED MORE COFFEE!..
__________________
-

Chaturbate Script - https://gfy.com/fucking-around-and-b...er-issues.html - Now supports White Labels
EddyTheDog is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-08-2015, 10:51 AM   #11
nm_
Confirmed User
 
Industry Role:
Join Date: May 2011
Location: San Diego
Posts: 328
Quote:
Originally Posted by EddyTheDog View Post
The code I posted should be used in a cron as well - The user would never have wait for an update...

However.....

You have got me back into this project and I am looking at using a DB so you can build up the database with all the cammers in it - Then mark them as on or off line using the XML file - That way you can build your own 'Cam Offline' and profile pages with the data...

As you collect more data you can create more complex pages with lots of info for the SEs.....

NEED MORE COFFEE!..
Already beat you to this haha :D.. My "version" of this has multi site functionality. Can essentially create better white labels of whitelabels
nm_ is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks

Tags
xml, $savefile, file, curl_setopt$ch, $xml_feed_url, $feed_updated, echo, testing, saved;, time;, no;, yes;, $ch, if$current_time, false;, curl_exec$ch;, curl_close$ch;, $xml;, $xml, $xml_feed_url;, curlopt_url, curlopt_header, $current_time, true;, curlopt_returntransfer
Thread Tools



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.