Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Jquery: chat system, what is the Ideal framework for this?

I want to implement a chat system for my site. The functionality will be very similar to facebook chat. The chats will be one to one based.

I know how to build the chat system using PHP, MySql and using JQuery. But my concern is that it won’t scale to large number of users in the long term.

Using JQuery I would be making requests every second to keep the chat window updated or if the user is sending a request to chat with another user. This will cause extra load on the server as the user base will increase overtime.

I’ve been told using PHP for this is not a ideal solution, that I should look into comet programming, which I never tried before.

My question is that are there any pre-build frameworks out there that I could use, or a better approach of building it?

I heard of NodeJs and APE but these are not supported by my server.

Thanks guys.

EDIT: after having word with my server guys, i might change my OS so i can run NodeJS. How good is nodejs is term of scalability and will it meet my needs?

like image 943
LazyDeveloper Avatar asked Sep 04 '11 17:09

LazyDeveloper


2 Answers

PHP and Comet are not mutually exclusive. Comet is just a technique of server push, so you don't have to poll ever second. You implement Comet in PHP & JS, it is not a separate programming language.

Although: I DO NOT recommend programming chat on your own, unless you need very specific features. It is time consuming and error prone. Use one of the pre-made solution, for example:

http://www.phpfreechat.net/

or java IRC chatroom. Google for more.

like image 71
Rok Kralj Avatar answered Oct 09 '22 14:10

Rok Kralj


As Rok Kralj says Comet is a paradigm and can be applied to different technologies. The PHP & Comet question is a good place to start if you want to look into this.

It tends to be commonly agreed that PHP doesn't scale too well as a realtime technology. Facebook, who are a PHP house (although ended up compiling their PHP down to C (or maybe C++) for efficiency). The most common solution is to use dedicated realtime technology for your realtime communication and keep this outside of your web server.

In terms of technology choice I would consider WebSockets since they have become the standard for realtime bi-directional communication. Some 'Comet' servers use WebSockets as a transport too and fallback to the less efficient HTTP Streaming or HTTP Long-Polling for older browsers.

If you'd consider using a hosted service, and don't want to be tied to just chat functionality, would like realtime notifications, visual collaboration or gaming to be added to your app at some point, then http://pusher.com, who I work for, offer a hosted realtime messaging service which you can easily implement your chat functionality.

like image 44
leggetter Avatar answered Oct 09 '22 14:10

leggetter