View Single Post
Old 11-04-2014, 07:08 AM  
sarettah
l8r
 
Industry Role:
Join Date: Oct 2002
Posts: 13,641
Quote:
It's Chaturbate's fault.The script works fine,but sometime chaturbate's xml feed doesn't load.If you check their site during that time,you will see they have problems too like cams not loading or site not loading at all.After they recover your site will recover as soon as your local xml gets updated.
Quote:
Originally Posted by k33n View Post
And..it's more like Sarettah's version since he was the one that helped me with speeding up the script.

Hey, just saw this.

If you are using the stuff we worked up in the other thread (https://gfy.com/showthread.php?t=1148389) then the easy fix is to not overwrite the local xml file if you do not get a good page back.

so in the section that we did up earlier we already check to see if we got nothing back, but the problem is that we might get something back but it is not the right something (404 error, 500 error, etc):

$flname="/server file path/filename";
$url="xml url";
$data=file_get_contents($url);
if(!empty($data))
{
file_put_contents($flname,$data);
}
else
{
echo "Did not get a file back<br>\n";
}

So, we need a way to check and see if we got the right something back. If you take a look at the raw cb xml file you will see that they have the data encapsulated in a "resource" tag (<resource>...</resource>):

<resource>
<is_new>False</is_new>
<iframe_embed>
<iframe src='http://chaturbate.com/affiliates/in/Jrvi/JkjyU/?track=embed&room=sexydea&bgcolor=white' height=528 width=850 style='border: none;'></iframe>
</iframe_embed>
<display_name>Dea</display_name>
....................
</resource>

So, we can check to see if we got a valid return by checking to see if there are resource tags in what we got back.

An easy way to do this is to use the substring count function (substr_count(haystack, needle)) and only rewrite the file if the resource tag is there.

if (substr_count($data,'<resource>')>0)
{
file_put_contents($flname,$data);
}

So the effect would be when we get a good file return we write the new file. When we do not get a good file return we keep the old file and show whatever is in there.

Now, this works if just chaturbate goes down but their cdn is still working. It will NOT show images if the cdn is down.

So the code would look like this:

$flname="/server file path/filename";
$url="xml url";
$data=file_get_contents($url);
if(!empty($data))
{
if (substr_count($data,'<resource>')>0)
{
file_put_contents($flname,$data);
}
}
else
{
echo "Did not get a file back<br>\n";
}


One disclaimer. This works fine up until cb changes the xml feed and gets rid of the resource tag ;p

Hope that helps

.
sarettah is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote