Page 1 of 1

Easy, understandable PHP/jQuery chat

Posted: Sun Jan 23, 2011 8:42 am
by Jackolantern
I was looking for a jQuery chat tutorial today to possibly use as a starting point for a more complex project. Most of what I found was far too complex for my needs, and tried to add all kinds of ICQ-style features. I did stumble across one good one that I actually felt was simple enough for a beginner to grasp and extend or integrate for their needs, so I thought I would post it here. Hope it is useful!

jQuery and PHP chat tutorial

Re: Easy, understandable PHP/jQuery chat

Posted: Thu Jan 27, 2011 7:54 pm
by hallsofvallhalla
thanks for posting this. good resource.

Re: Easy, understandable PHP/jQuery chat

Posted: Fri Jan 28, 2011 11:56 am
by Chris
It polls. This will eat bandwidth.

Re: Easy, understandable PHP/jQuery chat

Posted: Fri Jan 28, 2011 12:14 pm
by Jackolantern
Chris wrote:It polls. This will eat bandwidth.
True, but all of the more simple chat solutions do. Sure there are other techniques out there that don't poll, but they are far too complicated for beginners to understand. In those cases a beginner would just be copy'n'pasting and crossing their fingers that they don't get an error that they can't solve (which they won't be able to solve any of them). At least this way they can understand what they are doing and make corrections if need be.

Re: Easy, understandable PHP/jQuery chat

Posted: Fri Jan 28, 2011 5:25 pm
by alexander19
That's a nice chat example.

But what other way is there to send information between 2 or more users in jquery without the need of polling the server after a set time interval.

Re: Easy, understandable PHP/jQuery chat

Posted: Fri Jan 28, 2011 5:49 pm
by Jackolantern
alexander19 wrote:That's a nice chat example.

But what other way is there to send information between 2 or more users in jquery without the need of polling the server after a set time interval.
What Chris is alluding to is both Comet techniques and WebSockets. Both of which offer true "server push" technology. However, both are extremely complicated and far beyond the reach of a web development beginner, or even an intermediate developer, due to the use of advanced design patterns, the need for professional-level organization, and the fact that both techniques require server applications outside of the web server to use at their full potential.

Re: Easy, understandable PHP/jQuery chat

Posted: Fri Jan 28, 2011 9:04 pm
by alexander19
I see...it surely sounds pretty complicated.
Thx for the answer Jack.

Re: Easy, understandable PHP/jQuery chat

Posted: Fri Jan 28, 2011 9:24 pm
by Jackolantern
It is, but you don't necessarily have to roll your own. If you look up "WebSockets server" and/or "Comet server", you will find that there are both open source and commercial server offerings. While that makes it more accessible, using them is still likely out of the scope of a web development beginner. In the case where someone is just going through Halls' tutorials and they ask "How can I create my own custom chat", the linked tutorial above is the best resource I have found. Now if a more advanced user wanted to know what direction to head for a starting chat application that could be expanded out to support a MUD or something of similar complexity, I would point them towards either Comet or WebSockets servers.

Re: Easy, understandable PHP/jQuery chat

Posted: Sat Jan 29, 2011 12:19 am
by kaos78414
+1 for websockets! :P

It is complicated though. I've got one working application using websockets with a PHP backend, and it is frustrating to say the least. The neat thing about websockets is that it doesn't use some trick to make itself happen. It upgrades an HTTP connection to a TCP/IP connection, and can send data with only 2 bytes of overhead! 2 bytes! Wow! Ever look at HTTP overhead with Comet? It can get ridiculous. Comet opens two HTTP connections to allow for pushing data - using long-polling definitely takes its toll on a server.

You know Jackolantern, it's totally because you mentioned websockets awhile back that I'm using/learning it now. I should probably thank you, so thanks! :D

Re: Easy, understandable PHP/jQuery chat

Posted: Sat Jan 29, 2011 1:47 am
by Jackolantern
Haha, you're most welcome :)

And oh yes, WebSockets will stomp all over Comet when it is A. available in all major browsers and B. activated in all major browsers (Firefox and I think one other browser have deactivated them by default over security concerns). It is probably still going to be a while, as WebSockets is one of the largest, most complex additions in HTML 5, and there are just so many logistical concerns with trying to get 5 major browser providers to implement a version of WebSockets that they feel are secure enough to offer to their users. But as I mentioned over here, now is the time to get on the tool-type projects for HTML5 so that they are ready when HTML5 is live in all browsers! Is that where I mentioned it that made you start working on it, or something earlier?