Goose Posted April 9, 2007 Share Posted April 9, 2007 I am looking for people's opinions on if this is a good model for my chatting application or if they have any suggestions on a better and quicker way to do it. I am making a web bases chatting application that is using PHP server side scripting. I plan on using AJAX to bring about the live chatting feel. I have already written most of my custom AJAX scripts. Currently I am storing the chat in a log file instead of using MySQL database (my hope is that the file system will perform faster). I have a text file that basically holds a few bits of information in groupings. One grouping may look like this: user_id:goose timestamp:178454132 msg:this is a test message Each log file will have many of these, which is the chat for a given chatroom. My idea is to have PHP read the file in and display any new chats to the user. I want to be sure that this log file doesn't get too large so I was thinking I would only store a certain number of messages in the log file. So one of my questions, is there an easy way to remove some of the log file at the beginning of the file and keep the rest of the file intact? Any opinions are very welcome, thanks. Link to comment https://forums.phpfreaks.com/topic/46279-solved-web-based-chatting-app-ajax-php/ Share on other sites More sharing options...
trq Posted April 9, 2007 Share Posted April 9, 2007 Id'e be more inclined to use something like sqlite instead of a flat file, easier to maintain and delete messages via a timestamp if need be. Link to comment https://forums.phpfreaks.com/topic/46279-solved-web-based-chatting-app-ajax-php/#findComment-225144 Share on other sites More sharing options...
per1os Posted April 9, 2007 Share Posted April 9, 2007 SQL is definitely the way to go. I have created a few chats using similiar to the above except I did it like this: jack:_:date:_:Hey, how are you\n Each message was on a new line. Now for what you want with the truncating portion, simply put the new chats at the beginning of the file and just truncate the file length if it is over a certain size. Have fun with it. Link to comment https://forums.phpfreaks.com/topic/46279-solved-web-based-chatting-app-ajax-php/#findComment-225213 Share on other sites More sharing options...
Goose Posted April 9, 2007 Author Share Posted April 9, 2007 SQL is definitely the way to go... Do you mean sqlite is the way to go or MySQL? I just want this to run as fast as possible. I don't mind writing my own functions for making a flat file act like a database. Link to comment https://forums.phpfreaks.com/topic/46279-solved-web-based-chatting-app-ajax-php/#findComment-225234 Share on other sites More sharing options...
per1os Posted April 9, 2007 Share Posted April 9, 2007 Whichever you prefer, mysql; sql server; sql lite; oracle what ever floats your boat. If you want it to run as fast as possible you want it database driven. Link to comment https://forums.phpfreaks.com/topic/46279-solved-web-based-chatting-app-ajax-php/#findComment-225236 Share on other sites More sharing options...
Goose Posted April 9, 2007 Author Share Posted April 9, 2007 I wonder why I was under the impression that flat files would have faster access then Databases. Link to comment https://forums.phpfreaks.com/topic/46279-solved-web-based-chatting-app-ajax-php/#findComment-225257 Share on other sites More sharing options...
per1os Posted April 9, 2007 Share Posted April 9, 2007 No clue, let me tell you why. Think of this, you have a flat file storing 500KB of text. Now in order to erase one line in the middle of that file you have to open the whole file and find that entry. Looping through each caching all 500KB in memory, and than another admin comes in and edits the file, crap you just lost what he edited. Where as a database you pull only the entries you need fast without caching but maybe 1KB in memory instead of 500KB the query runs soo fast that if someone else modifys the same record, chances are it will not effect the record you just worked on or his. It takes about .0001 seconds to run a query. To read a file that size it would take a bit longer. That and if you need to "moderate" a message due to spam or inappropriate language, well the DB you can find that exact record in less than a second and delete that without messing up any of the other records. Databases are definitely superior in speed and ease of use as appose to a flatfile. Link to comment https://forums.phpfreaks.com/topic/46279-solved-web-based-chatting-app-ajax-php/#findComment-225288 Share on other sites More sharing options...
Goose Posted April 9, 2007 Author Share Posted April 9, 2007 Thanks!!! Link to comment https://forums.phpfreaks.com/topic/46279-solved-web-based-chatting-app-ajax-php/#findComment-225292 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.