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.
.