0

I'm into creating a php based web chatting system. About 1000 concurrent users across the world will be using it, so what would be the best tech to deploy?

As I did some research online, mainly I found systems using ajax and jquery for chatting while there're some using web sockets. I'm not sure as to which would work the best to suit my need. I prefer a real-time chatting system. If I were to use Ajax, will that be real time and as user increases, will there be any conflict?

Also, if I use HTML5 web socket, since the users going to chat from various nations around the globe, would it be faster? Let me give you a scenario.. If I use HTML5 push method which is hosted in some server in UK let's say, and the users from countries like India, Africa and China, will they face any downtime/ delay in sending and retrieving the messages?

Thank you for your time and detailed explanation in advance!

  • 1
    PHP really is not the right tool for a real-time web chat. PHP is supposed to process request and die, its GC is not very good and if you keep some kind of an event loop (which is pretty much necessary when developing a bi-directional service) running, you will eventually run out of memory, because PHP's GC will simply not pick up and invalidate variables. Node.js environment is far better suited for the problem you are trying to solve. For client->server AJAX requests, PHP is just fine. For server->client notification, PHP is a really crappy tool. – Andy Jun 5 '16 at 12:48
2

Ajax has better compatibility, but web sockets are more efficient and simpler (as you won't have to deal with issues about long polling, which can be a hassle to get right sometimes). These days, relatively few browsers support ajax but not web sockets, so my suggestion would be to do it that way, simply for the sake of simplicity.

Note that efficiency isn't likely to be your primary concern here; 1000 simultaneous users is not much (i saw that many using a single-server chat system over 20 years ago, now - the server that ran it was probably less than a tenth as powerful as my phone). Make your ementation straightforward and ready to evolve as your requirements change, is the critical thing.

I would, however, recommend not doing this in php if you have the choice. This is a highly concurrent application, and the last I checked (admittedly several years ago now) php's support for concurrency was somewhat lacking. If you prefer dynamic languages like php, maybe try either python or ruby for this project.

1

Php is fine for your project, even though there are better alternatives (hello NodeJS).

Ajax won't be real time. You'll have to manually make requests (even if they're made every X seconds) to fetch new datas. There won't be any conflict but there might be performance issue for you and your user.

Sockets are more interesting for your project because they'll update the UI when there is new data.

https://code.google.com/archive/p/phpwebsocket/ is the most widely used PHP class for web sockets.

  • can I know if I were to use Node.js, do I need to ask my customers install it on their pc before using my app or is there any other way? – 112233 Jun 6 '16 at 7:21
  • No, Node.js is on the back end of your application. Your users won't have to install it before they can use it. They don't have to install HHVM to go use Facebook either ;) – Steve Chamaillard Jun 6 '16 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.