views:

5243

answers:

7

I have searched on google for hours without finding a good and simple example of the comet technique using PHP. I just need an example that uses a persistent HTTP connection or something similar. I dont want to use a polling technique because I have something like that set up and not only is it difficult to work with and manage its a big hog of resources. Also I am using IIS7 not Apache. A good example would be really helpful so I can move on from this ugly polling technique.

,Thanks

+2  A: 

Never having used this technique and studying the Wikipedia article on the topic, "Long Polling" seems like the only viable solution. It sounds pretty simple to implement by infinitely looping and sleeping a script on the server. There's some actual code in the HTTP Streaming page linked to from the Wikipedia article.

Have you tried any of this and stumbled on specific problems?

deceze
+1  A: 

You can take a look at this article, it's a really good start to understand comet programming concepts.

You will find two examples on it. The first one use the iframe technique whereas the second one use a persistent connection.

dasilvj
A: 

You should use polling, or use a web server which is specially conceived for long requests and COMET, with a good JS backend:

function listen() {
    $.get("/mylongrequestfile", {}, function(data) {
     $("#mydiv").html(data);
     listen(); // then launch again
    }));
};

Remember that COMET is "wait for data, if there's data return and exit", so JS backend will have to parse the data and re-launch the process of asking the server.

In this example, if there is a server side problem or just a disconnection from the user side, the entire process will be broken (the function is only called if the request is successful)

Adrián
A: 

For IIS, there's WebSync. Since you're using PHP, however, you might be better off with WebSync On-Demand. Either one will give you the server-push you're looking for, and is simple to use. Check out this question as well, which is basically what you're after.

Here's a simple example of WebSync On-Demand in action using no scripting language. Simply open in two windows, and see the publish/subscribe in action.

To publish from the server, you can use the PHP api.

jvenema
A: 

you can take a look at this interesting chat site. http://www.weefoo.com

jquery and comet, rabbitmq stomp

hyliker
+1  A: 

I have a very simple example here that can get you started with comet. It covers compiling Nginx with the NHPM module and includes code for simple publisher/subscriber roles in jQuery, PHP, and Bash.

http://blog.jamieisaacs.com/archives/404

Jamie
+1  A: 

Check this out: How to implement COMET with PHP.
This is not using JQuery. It is made using PHP and Prototype. It is very easy to understand. I think you can made JQuery script easily after viewing this.

chanchal1987