views:

72

answers:

1

Hi There,

I'm trying to create a page on my website that shows newly uploaded items in real-time.

I was thinking that calling an Ajax Script every 3 seconds would be the best way to approach this, however my website does not get a new uploaded item that often. It is so variable too, anywhere between 30 seconds and 1 hour!

In addition, calling a script every 3 seconds would be pretty tolling on my server, especially if many people are on the same page.

I was looking around for something like a push notification for PHP. Although it seems far-fetched, I'm looking for something that when someone uploads something to the website, the upload script tells the feed page to update.

I saw something called COMET - Although reading through articles/tutorials has confused me even more.

So, what is the best way to implement a constantly updating page?

+1  A: 

On the server side, you'll need a script that can tell whether or not there is new content (eg: new files) based on a timestamp (eg: last request). On the client side, you have two options:

Polling aka Periodic Refresh:

This basically means having your client poll the server in intervals to check whether or not there is new data. What you want is to keep your requests and responses as light as possible. It could also help if run the script handling these requests in a separate process.

It will be up to you to tweak the interval to one that's acceptable for both the server and the user. You can also use a Heartbeat to tell whether or not the user is still active, so you can stop polling the server if the user left the window open but is off the computer.

HTTP Streaming aka "Comet":

Using this will require some more setup; but this is basically a long-lived connection from the client to the server and the server can "push" content to the client when necessary.

NullUserException