NeonCam Dollars
Surfers - Webmasters - Cam Models - Studios
About this tutorial

Caching the XML feed

The feed we are going to be using in these example are the complete All Online feed from Neon Dollars. I have also made it include every niche (girls, boys, couples, etc). Included in this feed is everything we need to know about the models; their name, bio, image, hair and eye colour, and a lot more besides. In EXAMPLE 1 you can see the array formatted output of this feed. I have created this file in the same way as I did in the parsing and XML feed tutorial. From example 1 you should be able to see all the data that we now have available to us to store and use.

Storing the XML feed

This is actually fairly easy and is all done within the cacheFile.php file. What this file does is reads the All Online XML feed, sorts it out into an array, opens a text files, writes to the text file, then closes the file. This might sound complicated, but using PHP we have built in functions that will do all this for us.

The cacheFile.php file looks like this.
<?php
if ( !touch( "allCache.txt" ) ) { echo 'You must create a file named allCache.txt and chmod it to 664 or 666'; die(); }
include( "clsParseXML.php" );
$xmlparse = &new ParseXML;
$xml = $xmlparse->GetXMLTree( "http://promo.neondollars.com/xml/allonline/v2.php?wm=8secure8&campaign=313&program=revshare&filter=1,2,3,4,5,6,7,8,9" );
$xml2=$xml["MODEL_LIST"][0]["MODEL"];
$cache = fopen ( "allCache.txt", "w" );
fwrite( $cache, serialize($xml2) );
fclose( $cache );
?>

I will now explain what each line of this simple file does.
if ( !touch( "allCache.txt" ) ) { echo 'You must create a file named allCache.txt and chmod it to 664 or 666'; die(); }
This line checks to see if the allCache.txt file exists. If it doesn't the TOUCH( ) function has a nice feature that will try and create the file for us. It it does exist, it will do nothing. If for some reason the script cannot make the file for us, then the script will stop and tell us that it aborted.
All servers are different, and I cannot possible go through each set up for every server. The script should create the file with no problems, but if you are finding that you get the error message it will either be because your server does not allow certain PHP functions (touch,fopen,fwrite,etc) or the CHMOD settings do not allow for the script to write the file. If you are not allowed to use the touch,fopen,fwrite functions, then you need to think about changing host. If the problem lies with the CHMOD settings you need to create an empty text file in notepad, save it as allCache.txt and upload it to your server. You will then have to make sure the file is CHMOD to either 664 or 666. You should NOT need to CHMOD the file to 777.

include( "clsParseXML.php" );
$xmlparse = &new ParseXML;
These two lines are the ones that call in the XML parse file that will do all of the sorting for us. More about this can be found on the other tutorial.

$xml = $xmlparse->GetXMLTree( "http://promo.neondollars.com/xml/allonline/v2.php?wm=8secure8&campaign=313&program=revshare&filter=1,2,3,4,5,6,7,8,9" );
This line tells us what XML feed we are going to be working with, and will be the one you need to change depending on what XML feed you are wanting to cache.

$xml2=$xml["MODEL_LIST"][0]["MODEL"];
This line simply cuts down the Array for us a little to make it easier to access.

The next 3 lines is where the script saves the array to the text file for us.
$cache = fopen ( "allCache.txt", "w" );
This opens our allCache.txt file ready for writing to and saves it as object $cache.
fwrite( $cache, serialize($xml2) );
This is the line that actually writes the data to the text file for us. Because we are dealing with an array, we pack all the data into a format that can be stored. This is what the serialize( ) funtion does for us. If we did not pack it up in this way, all that would be written to the text file would be the word "Array". Later on we will un-pack this data using the unserialize( ) function.
fclose( $cache );
This last line closes the file for us.

If you are using PHP5 on your server, you can replace those 3 lines with file_put_contents( "allCache.txt", serialize($xml2) ); which does everything for your, but for compatibility I have used the functions that will work on PHP4 and PHP5.

Running the file
Neon Cam Join the Neon Cams affiliate program and get $150 sign up bonus