Page 1 of 1

Control Growing Files

Posted: Fri Mar 07, 2008 5:10 am
by Largo65
Hi, here is my situation. I have an online flash game that tracks some data from the users.
Here's how it works: Flash sends data to PHP and PHP writes that data to an XML file.
Now what would be the best way to make sure that the XML's filesize doesn't grow too big? :?:
Can I add some code to the PHP that checks the XML's filesize and creates a new XML file if it gets too big?
I don't know PHP that well so I need some help. I know that I could just do this by hand regularly on the server, but I want to know if there is some way to automate this process, so if there is any other way please let me know. :)

This is my simple PHP code, that writes the flash data to PHP:

Code: Select all

<?php
$filename = "xmldata/trackingData.xml";
$raw_xml = file_get_contents("php://input");
 
print $raw_xml;
 
$fp = fopen($filename, "w");
fwrite($fp, $raw_xml);
fclose($fp);
?>

Re: Control Growing Files

Posted: Fri Mar 07, 2008 8:03 am
by Ricky Baby
2 methods:

you could check the "filesize(filename)" function

or

you could write to a file with the data assigned into the name e.g. "20080307_trackingData.xml" - use the date function to create the string.