Control Growing Files

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Largo65
Forum Newbie
Posts: 4
Joined: Fri Mar 07, 2008 4:44 am

Control Growing Files

Post 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);
?>
Ricky Baby
Forum Newbie
Posts: 1
Joined: Sat Feb 16, 2008 8:11 pm

Re: Control Growing Files

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