On Fri, Jun 3, 2011 at 7:11 AM, Adam Richardson <simples...@gmail.com>wrote:

> On Fri, Jun 3, 2011 at 1:50 AM, 李白|字一日 <calid...@gmail.com> wrote:
>
> > any idea?
> >
> > 2011/5/25 李白|字一日 <calid...@gmail.com>
> >
> > > hello,
> > >
> > > I am every interested in comet applications recently, and sadly found
> php
> > > is very weak in this area.
> > >
> > > i am just wondering if it is possible to write an extension to extend
> the
> > > ability of the php to easy the way to comet applications?
> > >
> > > if it possible for php to hold the connect from the client when it is
> in
> > > fast cgi mode or apache mod php mode?
> >
>
> Comet can use one of several techniques for low-latency data (
> http://cometdaily.com/about/), with the long-polling mechanism to simulate
> the realtime pushing of data from the server being a popular option:
> http://cometdaily.com/2007/11/15/the-long-polling-technique/
> http://en.wikipedia.org/wiki/Comet_(programming)
>
> <http://en.wikipedia.org/wiki/Comet_(programming)>To my understanding, PHP
> itself can accommodate this quite nicely. Merely start an infinite loop
> that
> breaks and returns new data when available. You'll probably have to adjust
> your web server settings and php.ini configuration to allow reasonably long
> requests for this particular need. However, when requests do time out, it's
> not a big deal as the javascript should be set up to reinitiate a new
> request if that happens, just as it would if the request returned new data
> and closed, giving the appearance of a continuous stream of pushed data.
>
> This all said, if you wanted to write an extension to facilitate long
> polling, you could, but given the natural latencies for these requests, I'm
> not sure you'd find a significant benefit.
>

One word of caution... While PHP can be used to implement long polling, bear
in mind that PHP is fairly expensive in terms of resource usage per
connection. Unless you're swimming in servers or only expecting a few
concurrent connections at any one time, I'd recommend using something that
holds multiple connections per process, rather than one process per
connection.

IMO, web-based PHP is not the right solution to this problem. You could
write a select-based comet server in PHP, but it definitely wouldn't be in
my top 10 language choices.

I've just seen a later email in this thread that mentions that this is a
chat-type system. Watch this and have your mind blown...
http://vimeo.com/20605470 - at some point he describes how to write a pretty
efficient chat server in PHP using ZeroMQ, but the whole thing is worth
watching.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

Reply via email to