Hi guys... i would like to ask what are the fastest/effective way on updating my database contents?
Assuming that I'm creating a chatting website where user's online can chat with their friend live just like facebook have. And one of the facebook features is that you can view all your online friends in realtime. So i was wondering on how to be able to have the effective approach to let you chat with your friends and let you know that one of your friends have login?
What im thinking on the chat system is that when i click on the send button it will update the database and assuming that i have MSSQL or MySQL as my database. So assuming that when i hit send the message will be save on my database then on the other side (
the one im chatting with) they will have a function that keeps on checking the database of new message for them by their chatmate. But here is the problem. I just recently read that on "
MySQL" they have this queue process where "
IF" 1000 users send an update command to the database almost at the same time so the tendency is that MySQL will queue all those update command (
from what i read MySQL by default can only handle about 200+ command at the same time more than that all command will be queue)...
So now the problem is if 1000 update command was send at the same time on the database it will queue the remaining 700+ user command. so my chat system will not function as expected and will not update a new message in real time because your message may be still in queue...
1.)
I want to ask what are the effective way to create the realtime chat system?
2.)
is there a way to create it without going through the database and keeps on updating the database content? I would really appreciate your ideas guys...
This is what im thinking of how to accomplish this... please correct me if I'm wrong
im thinking of combining ajax, jquery, php to create this chat system..
In my jquery/javascript/ajax code
=============================================================================
$(document).ready(function(){
setTimeout("getMessages()",1000);
$("#sendMessageButton").click(function(){
$.ajax({
type: 'POST',
url: 'send_message.php',
data: {
'message' : message,
'user_id': u_id },
dataType: 'json',
success: function(response){
if(response != ""){
}
}
});
});
function getMessage(){
$.ajax({
type: 'POST',
url: 'get_message.php',
data: {
'message_id' : id,
'user_id': u_id
},
dataType: 'json',
success: function(response){
if(response != ""){
}
setTimeout("getMessages()",1000);
}
});
}
});
======================================================================
in my get_message.php
?>
=====================================================================
in my send_message.php
<?php <br mode="hold" /?>
?>
Is my approach right or do i need to modify something?