5

I set myself a challenge today to write a jQuery chat in under half an hour. It eventually took me 40 minutes.

However, I want to improve it so the load on the server and browser isnt horrendous.

Currently the user types into a text box, presses enter, this data is sent to a .php file which updates a mySQL table and outputs all the rows on the table.

There is a set Interval on the div every two seconds to update if anyone said anything without the user pressing enter.

I just wanted to know thoughts on how to do perform this in a better way, or the most efficient way. I want to understand the best technology to use and why.

Thanks for all your input, I love stack overflow, its been invaluable to me.

9
  • 4
    Go and read up on Node.js and SignalR. Commented Aug 1, 2012 at 16:56
  • You could use Ajax Commented Aug 1, 2012 at 16:59
  • That is what I am doing with .load() Commented Aug 1, 2012 at 17:00
  • @mdm do you have links to these, by any chance? Commented Aug 1, 2012 at 17:01
  • yeah i cant find a decent tutorial on it, I have no idea what I am reading. Commented Aug 1, 2012 at 17:05

1 Answer 1

2

Using ajax polling for a chat application with the "php back"/"javascript front" technology stack will inevitably result in a heavy server load. Http is just not designed for that kind of communication, and if you're using apache (as I assume) there is a really heavy overhead for each request.

As some of the commments indicated, you could investigate using a full stack javascript framework (i.e. Node.js on the backend).

When I had the task of accelerating an existing chat application with php backend and Javascript frontend (using periodic ajax poll), I ended up using a 3rd party server side product to handle lightweight XMPP requests. This server side product was OpenFire, but you could use eJabberd for even better performance - OpenFire is easier to set up and maintain though. The results were more than satisfactory, server load dropped significantly, and messages were delivered instantly for ~1000 online users chatting wildly away (on a less-than-average performance dedicated linux box).

It's hard to explain all the tiny details within a SO answer's scope, but luckily Ben Werdmuller @ IBM went out of his way to write an awesome tutorial on this topic.

Sign up to request clarification or add additional context in comments.

1 Comment

As a note: XMPP is actually what facebook use to do their chat, so maybe that's a sign of its scalability

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.