Easy, understandable PHP/jQuery chat
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Easy, understandable PHP/jQuery chat
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
jQuery and PHP chat tutorial
The indelible lord of tl;dr
- hallsofvallhalla
- Site Admin
- Posts: 12023
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Easy, understandable PHP/jQuery chat
thanks for posting this. good resource.
Re: Easy, understandable PHP/jQuery chat
It polls. This will eat bandwidth.
Fighting for peace is declaring war on war. If you want peace be peaceful.
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Easy, understandable PHP/jQuery chat
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.Chris wrote:It polls. This will eat bandwidth.
The indelible lord of tl;dr
-
- Posts: 180
- Joined: Fri Apr 02, 2010 1:05 pm
Re: Easy, understandable PHP/jQuery chat
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.
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.
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Easy, understandable PHP/jQuery chat
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.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.
The indelible lord of tl;dr
-
- Posts: 180
- Joined: Fri Apr 02, 2010 1:05 pm
Re: Easy, understandable PHP/jQuery chat
I see...it surely sounds pretty complicated.
Thx for the answer Jack.
Thx for the answer Jack.
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Easy, understandable PHP/jQuery chat
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.
The indelible lord of tl;dr
Re: Easy, understandable PHP/jQuery chat
+1 for websockets!
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!
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!
w00t
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Easy, understandable PHP/jQuery chat
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?
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?
The indelible lord of tl;dr