views:

45

answers:

2

I am trying to create a new Notice Alert using PHP and Javascript. Suppose that a 100 users are currently logged into to the Online Notice Board Application and any One user posts a new notice. I want an immediate alert signal on all the users screen. I know, that the simplest way of doing it is to constantly Ping the server but I don't want to do it as it will slow down the server. Moreover, I am on a shared host. So I don't have access to any Socket Port. That means, I cannot establish any direct Socket Communication Channel from the Server to the User Machine.

Can any one suggest me some other solution to this kind of problems???

+3  A: 

This is a COMET application. Google for COMET and you should find lots of information. Basically there are two techniques for retrieving asynchronous notifications over HTTP. The first is to ping the server, which you've already said you don't want to do. The other technique is to send a request to the server and have the server respond only when there is some data. In other words, instead of pinging once a second and only getting a message after 50 pings and 50 seconds, the server simply holds the first request for 50 seconds, until there is something to send, then responds. There are tools that will do all this for you.

Willis Blackburn
But there's an issue of maximum number of opened connections for http server. On shared hosts this will be much bigger issue than server load, I think.
Tomasz Struczyński
There's definitely no free lunch here. Pinging consumes CPU time while the long-request method consumes resources. Most servers that support COMET allow the application to put a request on ice in some manner, so that it at least doesn't use a thread or process while it's waiting for a response. It still uses a file descriptor, but the server has 1,000 of those at least. If you have 1,000 users all waiting for a COMET response then you're in good shape from a business perspective and can probably get some more servers.
Willis Blackburn
A: 

Why do you ask for another solution if you already have one?

Why do you ask for solution of the imagined (supposed) problem, not a real one? From what you know it will slow down a server? From the experience and exact profiling? I suppose no.

Col. Shrapnel