View Single Post
Old 12-01-2014, 09:09 AM  
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,053
Quote:
Originally Posted by sarettah View Post
funnytimecpl, here is what I think might be a much more efficient way for you to do what you are trying to do.

One note, if you are already running something like nomoneyinporn's script then this could probably be integrated right into it, not sure where without reviewing the script some.

First, let's split it into 2 parts. The first part will run from cron periodically. You could set it for once a minute, once every 2, whatever.

In the cron piece, we pull in the feed. Check to see if we are online. Write a file if we are on line. If we are not on line we delete the online file if it is there. End of program.

Make a folder in your domain space on the server called online.

Put this code (with the proper modifications to the vars) into a php file in the online folder:

Code:
<?php
$user_to_find="myusername";
$online_file="online.txt";
$cams = new SimpleXMLElement('http://chaturbate.com/affiliates/api/onlinerooms/?format=xml&wm=AFFILIATELINK', null, true);
$online = false;
foreach ($cams->xpath('//username') as $username) {
if($username=="myusername")
{
  $outfile=fopen("online.txt");
  =fwrite($outfile,'1');
  =fclose($outfile);
  $cams=null;
}
else
{
  if(is_file("online.txt"))
  {
    unlink("online.txt");
  }
}
?>
Now, to test that from a browser you will probably have to change permissions so the script can write the file. So 777 the folder, test. Once the file is being written and deleted as expected put the permissions back to whatever they were when you started.

Or you can put some htaccess in there allowing just the server and your ip to have access that way the cron can run and you can test from a browser but noone else can access it.

Set up your cron to run that php file however often you want to run it.

Now, wherever you want the embedded room to appear, instead of all the other code we did earlier use something like:

Code:
<?php
$iframe_code="My_iframe_code";
$top_room_iframe_code="top_room_iframe_code_goes_here";
$online_file="online/online.txt";
if(is_file($on_line_file))
{
  echo $iframe_code;
}
else
{
  echo $top_room_iframe_code;
}
?>
The result should be that your embedded page should load a whole lot quicker then it did using the earlier code.

The other issue that started this thread could be handled that way as well, with a little modification to handle the multiple usernames being checked for, etc....

Hope that helps.

.

For info for anyone reading this thread.

I have several errors in the code here. Comes from throwing it up quickly while doing a project in another language. Shit happens you know. ;p

Here is a fix for the code in the top code box:

Code:
<?php
$user_to_find="myusername";
$online_file="online.txt";
$cams = new SimpleXMLElement('http://chaturbate.com/affiliates/api/onlinerooms/?format=xml&wm=AFFILIATELINK', null, true);
$online = 0;
foreach ($cams->xpath('//username') as $username) {
if($username=="myusername")
{
  $outfile=fopen($online_file, 'w'); // added the 'w' to make this writeable.  Changed to use file varname
  fwrite($outfile,'1');  // removed the '=' at the beginning.  different language
  fclose($outfile);   // removed the '=' at the beginning.  different language
  $cams=null;
  $online=1;
}
}
// moved this outside the for loop so we do not overwrite the file every time
if(!$online)
{
   if(is_file($online_file))
  {
     unlink("online.txt");
  }
}

?>
.
__________________
All cookies cleared!
sarettah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook