Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 23rd Mar 2015, 05:21 AM   #1
DA Soft Crew
 
Join Date: 2015
Posts: 12
Thanks: 1
Thanked 1 Time in 1 Post
Default
Best way to make a chat
Share on: 
fb share twitter share gplus share more share

Hi all,

I have recently developed a website where i created a custom chat, where there is a main chat room and then the ability to click on an user to chat privately.

I did it in the most simple way, with short polling, making ajax requests every 1-2 seconds to update the last activity date for keeping track of online users and to get the latest users in the chat room and the latest messages. It is done in PHP+MySQL.

This is definitely not the best way to do it and i know that, it was just my first chat app and i wanted to get it done asap with my current knowledge.

Now lets say the site will be having a few hundreds or even thousands of users at the same time, that would have a big impact to the MySQL, right?

Would there be any server that is not too expensive and that could support such amount of users?

Would you suggest of doing long polling? Or would that not be enough either?

Or would i need to use some other technology much better for this kind of apps, like NodeJS + MongoDB?

Looking forward to your suggestions.

dasoftcrew is offline  
Unread 23rd Mar 2015, 03:20 PM   #2
HyperActive Warrior
War Room Member
 
emptee's Avatar
 
Join Date: 2014
Location: New Zealand
Posts: 210
Thanks: 25
Thanked 81 Times in 71 Posts
Default
Re: Best way to make a chat
Share on: 
fb share twitter share gplus share more share

Hey mate,

My advice would be to not reinvent the wheel if possible.. IRC has been around for decades and still works great!

There are a few java clients, a few flash clients, and a few websocket clients around, which you could use straight away - otherwise if these don't suite you, you could write one up in JS easier than making a new system from scratch, in my opinion anyway...

As an added bonus, your users would then also be able to connect using third party clients, which some of them may prefer.

Otherwise, if you insist on doing it all from scratch.. and you don't want to use websockets.. long polling would be the way to go.

Again, I would strongly urge you to not go down the mysql/mongodb route if at all possible - scaling could become an issue pretty quickly.

Cheers,
Michael

emptee is offline  
The Following 2 Users Say Thank You to emptee For This Useful Post:
Unread 23rd Mar 2015, 03:31 PM   #3
HyperActive Warrior
War Room Member
 
emptee's Avatar
 
Join Date: 2014
Location: New Zealand
Posts: 210
Thanks: 25
Thanked 81 Times in 71 Posts
Default
Re: Best way to make a chat
Share on: 
fb share twitter share gplus share more share

Oh, I forgot to mention.. The HTTP/PHP stack probably wouldn't be much of an issue, even a smallish VPS should be able to put up with the request abuse.. it's the queries that will kill you, eg.

Assuming you have your clients polling every 2 seconds, either from a long PHP session or from individual AJAX requsts..

100 users @ 1 request per 2 seconds = 50 UPDATES + 50 SELECTS = 100 queries/second

Scale that up a bit and you can see the problem! And we're not even talking about checking authentication, updating statistics... or even actually chatting yet!

emptee is offline  
Unread 23rd Mar 2015, 05:11 PM   #4
Designer & Developer
 
mikea12's Avatar
 
Join Date: 2014
Posts: 44
Thanks: 0
Thanked 3 Times in 3 Posts
Default
Re: Best way to make a chat
Share on: 
fb share twitter share gplus share more share

Best way is socket.io hands down. I am available for hire, and can show you some realtime chat applications I have built. Working on one for android right now.

http://postimg.org/image/ln7f79xct
mikea12 is offline  
Unread 24th Mar 2015, 01:15 AM   #5
DA Soft Crew
 
Join Date: 2015
Posts: 12
Thanks: 1
Thanked 1 Time in 1 Post
Default
Re: Best way to make a chat
Share on: 
fb share twitter share gplus share more share

Thanks for your suggestions guys. I have one question: I heard a lot of people saying that websockets are not working in all browsers yet or something like that. Is it true? Or is there a workaround to make it work in all browsers?

dasoftcrew is offline  
Unread 29th Mar 2015, 02:23 PM   #6
HyperActive Warrior
War Room Member
 
Join Date: 2009
Posts: 145
Thanks: 3
Thanked 48 Times in 24 Posts
Default
Re: Best way to make a chat
Share on: 
fb share twitter share gplus share more share

Websockets do currently work for modern browsers. For IE it's 10 and up. It doesn't work for Opera Mini, though, that isn't in much use anyway.

I would use websockets for this if you can. It's actually a pretty light task if you use node. That's the default tutorial on most node sites these days.

Storage for the chat is an issue.

You can look into services like Firebase which are designed to provide realtime capabilities without needing to set up the infrastructure.

723Media is offline  
Unread 29th Mar 2015, 08:14 PM   #7
Advanced Warrior
 
Join Date: 2010
Location: Lawrenceville GA
Posts: 685
Thanks: 52
Thanked 153 Times in 117 Posts
Default
Re: Best way to make a chat
Share on: 
fb share twitter share gplus share more share

Yup web sockets or a service like ape.

rts2271 is offline  
Unread 31st Mar 2015, 06:30 AM   #8
Mr Write
War Room Member
 
sethczerepak's Avatar
 
Join Date: 2009
Location: The Beach
Posts: 1,854
Thanks: 881
Thanked 1,222 Times in 670 Posts
Default
Re: Best way to make a chat
Share on: 
fb share twitter share gplus share more share

Originally Posted by dasoftcrew View Post

Hi all,

I have recently developed a website where i created a custom chat, where there is a main chat room and then the ability to click on an user to chat privately.

I did it in the most simple way, with short polling, making ajax requests every 1-2 seconds to update the last activity date for keeping track of online users and to get the latest users in the chat room and the latest messages. It is done in PHP+MySQL.

This is definitely not the best way to do it and i know that, it was just my first chat app and i wanted to get it done asap with my current knowledge.

Now lets say the site will be having a few hundreds or even thousands of users at the same time, that would have a big impact to the MySQL, right?

Would there be any server that is not too expensive and that could support such amount of users?

Would you suggest of doing long polling? Or would that not be enough either?

Or would i need to use some other technology much better for this kind of apps, like NodeJS + MongoDB?

Looking forward to your suggestions.
You should look into this plugin...

Facebook style jQuery plugin for chatting

I've used it to build chat features in just a few hours, on multiple sites. Most of them on shared servers and it works just fine.

sethczerepak is offline  
Unread 31st Mar 2015, 11:32 PM   #9
Newbie
 
rosario1990's Avatar
 
Join Date: 2015
Location: Bangladesh
Posts: 467
Thanks: 42
Thanked 56 Times in 51 Posts
Default
Re: Best way to make a chat
Share on: 
fb share twitter share gplus share more share

I've been using chatwing on my site and it works very well, it has a ton of customization options and the really good part that i have not seen on any other software is it has mobile app so i have chatwing android app on my phone and i can get alerts when people send me private message or are chatting in my rooms. very cool.
rosario1990 is offline  
Unread 4th Apr 2015, 01:51 PM   #10
Warrior Member
 
Join Date: 2015
Location: USA
Posts: 10
Thanks: 19
Thanked 0 Times in 0 Posts
Default
Re: Best way to make a chat
Share on: 
fb share twitter share gplus share more share

Websockets are more "efficient" than long-polling in the sense that polling is still dependent on HTTP. This means all the overhead of HTTP, including headers, cookies, etc. is transmitted, whereas websockets won't send that extra information.

Curtnielson is offline  
Unread 9th Apr 2015, 08:37 PM   #11
Newbie
 
rosario1990's Avatar
 
Join Date: 2015
Location: Bangladesh
Posts: 467
Thanks: 42
Thanked 56 Times in 51 Posts
Default
Re: Best way to make a chat
Share on: 
fb share twitter share gplus share more share

Originally Posted by Curtnielson View Post

Websockets are more "efficient" than long-polling in the sense that polling is still dependent on HTTP. This means all the overhead of HTTP, including headers, cookies, etc. is transmitted, whereas websockets won't send that extra information.
May be right you're in some cases. I tried many of it. But can't find any thing like chatwing. It's superb! Chatwing has many more features for this it stunning from another one.
rosario1990 is offline  
Closed Thread


Bookmarks

Tags
chat, make


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 04:34 PM.