|
-
Nov 3rd, 2011, 04:11 AM
#1
[RESOLVED] [jQuery & PHP] Long polling or Comet programming in Chat ?
Hi guys 
I have developed a chat application using PHP and jQuery. So, at the moment, my chat app would poll the server every 2.5 seconds, with the last message's id as GET request. And in the server side, the script will establish a db connection and check whether any new messages are arrived which is greater than the message_id that was received through GET request.
If found, echo the new messages. Otherwise, echo empty string. So far it works okay.
But I have heard that we could make the polling efficient by using a long polling method or a comet programming method. Based on the my research(search done on Google ), I found that comet is not cross-browser supporting. So, I thought about the long polling mechanism. But what it does is, it would use a loop in the serverside, checking for new data arrivals and if so, echo it. Otherwise, stay in the loop until new messages comes.
But wouldn't it eat server resource ?
Do you think long polling would be the best ? Or do you know some other technique which is more efficient ?
Thanks
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Nov 3rd, 2011, 07:39 AM
#2
Re: [jQuery & PHP] Long polling or Comet programming in Chat ?
 Originally Posted by akhileshbc
But what it does is, it would use a loop in the serverside, checking for new data arrivals and if so, echo it. Otherwise, stay in the loop until new messages comes.
But wouldn't it eat server resource ?
This is a technique I have used in the past and it worked reasonably well, although I agree it is a little intensive on the server side. A (possibly) better option would be to use sockets to communicate between the database and listener processes on the server side, rather than constantly polling the database. But I'm not sure whether you would see much or any benefit from this, and unless you were running a very busy server I'm certain it would not be worth the effort. I would stick with the 'Comet' (long poll) model myself.
Last edited by penagate; Nov 3rd, 2011 at 07:46 AM.
Reason: benefit -> effort
-
Nov 3rd, 2011, 12:06 PM
#3
Re: [jQuery & PHP] Long polling or Comet programming in Chat ?
Thanks
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Nov 4th, 2011, 02:08 AM
#4
Re: [RESOLVED] [jQuery & PHP] Long polling or Comet programming in Chat ?
Just another doubt: I'm now staring at this code - http://lxcblog.com/2010/10/17/jquery...aging-example/
So, that will poll the server script for a new message and the server will loop until a new message is found.
But what happens if we want to post a message to that same PHP page ? 
Isn't it still busy with the loop ?
Edit:
I think, I got it. When a PHP page is requested, it would create an instance of it. When another one request the same page, a new instance will be used. And at the end of the script, the current instance will be disposed. Isn't it ? I'm confusing my mind by mixing desktop and web programming !
Last edited by akhileshbc; Nov 4th, 2011 at 02:56 AM.
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Nov 4th, 2011, 06:13 AM
#5
Re: [RESOLVED] [jQuery & PHP] Long polling or Comet programming in Chat ?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|