solution for COMET and PHP

冷暖自知 提交于 2019-11-27 20:19:20

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...

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.

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.

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=_t&hl=ru&ie=UTF-8&layout=1&eotf=1&u=http://dklab.ru/lib/dklab_multiplexor/&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://dklab.ru/lib/dklab_realplexor/

Taha

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.

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

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)

Anton N

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

Readme.txt in english is provided in the package.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!