0

I have a requirement where I need to send continuous updates to my clients. Client is browser in this case. We have some data which updates every sec, so once client connects to our server, we maintain a persistent connection and keep pushing data to the client.

I am looking for suggestions of this implementation at the server end. Basically what I need is this: 1. client connects to server. I maintain the socket and metadata about the socket. metadata contains what updates need to be send to this client 2. server process now waits for new client connections 3. One other process will have the list of all the sockets opened and will go through each of them and send the updates if required.

Can we do something like this in Apache module: 1. Apache process gets the new connection. It maintains the state for the connection. It keeps the state in some global memory and returns back to root process to signify that it is done so that it can accept the new connection 2. the Apache process though has returned the status to root process but it is also executing in parallel where it going through its global store and sending updates to the client, if any.

So can a Apache process do these things: 1. Have more than one connection associated with it 2. Asynchronously waiting for new connection and at the same time processing the previous connections?

ArtemGr
  • 11,684
  • 3
  • 52
  • 85

2 Answers2

1

This is a complicated and ineffecient model of updating. Your server will try to update clients that have closed down. And the server has to maintain all that client data and meta data (last update time, etc).

Usually, for continuous updates ajax is used in a polling model. The client has a javascript timer that when it fires, hits a service that provides updated data. The client continues to get updates at regular intervals without having to write an apache module.

Would this model work for your scenario?

More reasons to opt for poll instead of push
Periodic_Refresh

Community
  • 1
  • 1
Tim Hoolihan
  • 12,316
  • 3
  • 41
  • 54
0

With a little patch to resume a SUSPENDED mpm_event connection, I've got an asynchronous Apache module working. With this you can do the improved polling:

  1. javascript connects to Apache and asks for an update;
  2. if there's no updates, then instead of answering immediately the module uses SUSPENDED;
  3. some time later, after an update or a timeout happens, callback fires somewhere;
  4. callback gives an update (or a "no updates" message) to the client and resumes the connection;
  5. client goes to step 1, repeating the poll which with Keep-Alive will use the same connection.

That way the number of roundtrips between the client and the server can be decreased and the client receives the update immediately. (This is known as Comet's Reverse Ajax, AFAIK).

ArtemGr
  • 11,684
  • 3
  • 52
  • 85