Jump to content

[SOLVED] web based chatting app (AJAX + PHP)


Goose

Recommended Posts

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

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.