I have a "board"/"dating"-service where my users can send messages to each others(school-project).

I store all the messages in a "Users/$username/messages/inbox/"-folder as .txt files named 1.txt, 2.txt, 3.txt -----> 100.txt.

I would like to limit the number of messages to 100, and I guess I could manage to program that by myself(I hope), but my big problem is this:

If a user wants to erase say message nr#46(46.txt), how can i manage to rename message 47-100(47.txt --- 100.txt) to have a new name like 46-100(46.txt --- 99.txt) ??

Do I have to move them to a temp-dir, rename all the files in a loop and erase the contents of my "inbox"-dir and put the files back in there, or does anyone have a good solution ???

    you should really think about using a database (mySQL) to store this type of stuff instead of individual text files. It will be much easier to manage and you won't have to rename files. If you want to limit users to 100 messages just run a query that extracts the COUNT() of the messages and display and error if the count is greater than 100.

      d-base would be best, but, u could always create a batch file on the fly and run it through php (i believe) which in my eyes would be just as easy as doing it through php cuz i don't exactly know how to do that in php. but, mysql would be ideal for this as opposed to text files, (wondering if there's a reason ur not using it?) 🙂 good luck!

        I most certainly agree that storing this type of data in a database would be the easiest way, but if you consider the fact that is a school project and that we have to develop systems/sites that are "scalable"(..eh...) = can work "smooth" with 1000 users(++), I believe that approx 200.000 messages(10010002(in/outbox)) would slow down the site performance if every user has to send a query to the db ?
        ..or am I on the wrong track here ?
        ...I am i newbie, so any comments would be appreciated :-)

        Here is the function I made to make it work, and by the testing I have managed to do so far(between supper and cigarettes), I believe it works pretty well at least in my case:

        
        function rename_messages($user, $message, $path, $numofmessages){
        	unlink("".$path."".$message.".txt");
        		$rnm = $message+1;
        		for($x = $rnm; $x <= $numofmessages; $x++){
        			rename("".$path."/".$x.".txt", "".$path."/".($x-1).".txt"); 
        			}
        

        Does this seem to be a good solution to any of you guys with experience ??

        -please give me some feedback-

          php and mysql is ideal for this, i think that it could handle it without a sweat, you just might have to make the max threads to the dbase higher than 50 (because i think that's what it defaults to in mysql, could be wrong though) i think though, that it would handle it just fine, otherwise, why would people be using php/mysql on the web if they weren't planning on having lots of hits? 😃

            Write a Reply...