tags:

views:

488

answers:

8

Is there a real solution for COMET AND PHP combination? Basically, I've come to a point that I need to update a user home page periodically whenever there is new data in the database. As far as I understand, I need to open a persistent connection between my server and my clients browsers to update the contents of their home page as soon as new info. available without dedicating a lot of resources but I had no luck finding anything clear about this issue. I read many articles suggests that PHP is not a good language to implement COMET. My web application is completely programmed in PHP and I don't want to learn another language but if I'm forced to, Would you suggest a good language to start with? Do you think that I can program an interface just to handle this issue?

Thanks in advance.

A: 

You don't have to learn a new language to implement such a feature.

For example, you could use Quercus (Java implementation of PHP) and implement a server Comet application using the JVMs memory management model.

Luca Matteis
Very interesting to hear that there is a PHP in JAVA implementation. As what I've read in docs, It's really more faster than traditional PHP-APACHE module but I'm really confused. As far as I understood, Resin will serve PHP pages not apache but how can I implement a Comet server application using JVM as you said? Should I make use of some JAVA functions. Forgive me, I'm a newbie in this technology and I have no experience whatsoever in JAVA. Thanks
codemaker
A: 

Hi, There are solutions you need:

  1. almost COMET solution (uses php and one file written with perl): http://translate.google.com/translate?js=y&prev=%5Ft&hl=ru&ie=UTF-8&layout=1&eotf=1&u=http%3A//dklab.ru/lib/dklab%5Fmultiplexor/&sl=ru&tl=en

  2. exact COMET solution in php (this is what you want, I think): http://translate.google.com/translate?hl=ru&sl=ru&tl=en&u=http%3A//dklab.ru/lib/dklab%5Frealplexor/

Tyler
Thanks a lot for the info.I'm going to try it out.
codemaker
A: 

You should try Dmitry Koterov's Realplexor, which is a comet server, that provides Javascript and PHP APIs.

Download from github:

http://http://github.com/DmitryKoterov/dklab_realplexor/

Readme.txt in english is provided in the package.

Anton N
Sorry, the link is dead.
codemaker
it works for me. try to download from this page: http://github.com/DmitryKoterov/dklab_realplexor/
Anton N
+1  A: 

The times I've heard people say that PHP was not well suited for COMET (like you said yourself) was because of the way webservers and PHP work -- mostly, because there is one process per page, which means if you want 200 users connected to your server, you'll need 200 processes (which can quickly become a problem for a couple of hundred more users).

Maybe a solution to that problem would be to use nginx_http_push_module ?

I've not tried it (yet ?), but it might be just what we need...

Pascal MARTIN
Interesting. Is there any examples of how to make use of it. for example, how to push data from PHP script to a broswer?
codemaker
I've not seen any PHP example yet, unfortunatly ;-( ;; I might try one day or another, but not in the immediate future... Still, if you try yourself, and/or find anything interesting, I'm interested by what you may find ;-)
Pascal MARTIN
A: 

You would first need to understand what is a comet application like. The concept involved in building a comet application are explained at wiki at Comet (programming)

What you need to understand is that you can use any programming language to build a comet application as long as it follows the concepts explained at wiki

1.Ajax with long polling

2.Streaming

You can check some sample code at Simple “Long Polling” example code

Now coming to the problems -

1.You use ajax long polling then the browser(ajax request) would keep polling the server for data. This may eat up memory on the server or slow down the browser after some time.

Few Suggestions

JQuery PeriodicalUpdater (AJAX long polling/server polling)

Handling Long Polling

RobertFischer / JQuery-PeriodicalUpdater

What you need to check to implement this -

a) How often do you expect data to be updated on the server.

b) How much time the server side script would run to check, fetch and process data before sending it to the client side.

2.You can implement streaming by using the following -

How to implement COMET with PHP

Lightstreamer Dojo

Dojo Charting + Lightstreamer Comet Demo

Demo

Ajax Push Engine or The APE Project

What you need to check for this -

a) Will your hosting provider allow you to install these on hosting servers

b) Your RAM and Bandwidth utilization (You will need a dedicated server with package that gives you lots of RAM and Bandwidth)

It depends on what and how your requirements are. You will have to analyze and approach.

If what you are implementing is a small application you can go for Ajax Long polling given the fact that you analyzed and handled the negatives of this approach.

If you have a large application you can go for steaming.

Taha
A: 

I was working on a school project and ran into the exact same problem. Because each PHP process has so much memory overhead, it's impossible to support to many connections per box. It was at this point I decided to switch to using BOSH and XMPP. This is a rather new "wave" of technology but there is already quite a few libraries to help you on your way. I would suggest using Strophe and XMPPHP. Then your clients can connect to a BOSH server (I'm using Openfire) and that can scale to thousands of active connections per server.

Kendall Hopkins
A: 

Ajax with long polling is a easy solution, there are plugins in jquery and any other major js framework to help you do this.

Jinah Adam
Comet is long polling Ajax, PHP doesn't let you tinker with the typical page/request model so it's difficult to get good results with Comet and PHP
Michael
A: 

Node.js seems like a pretty sweet solution for stuff like this. (Still a little gamey for production but cool all the same). PHP is a horrible environment for stuff like this, you have to change the way the server interacts with requests because you are no longer immediately responding. Python has a handful of servers like Twisted that are great for this because they let you be the server. No matter what language you write it in you've got to alter the typical request/response model. (Glassfish's Grizzly Comet server does this for Java as an example)

Michael