How to make a permanent update page?

I am trying to create a page on my website that shows new uploaded items in real time.

I thought that the best way to approach this would be to call Ajax Script every 3 seconds , however, a new uploaded item often does not appear on my site. It is so variable, somewhere between 30 seconds and 1 hour!

Also, calling Script every 3 seconds will be pretty tolling on my server, especially if many people are on the same page.

I was looking for something like push notifications for PHP. Although this seems far-fetched, Iโ€™m looking for something that when someone uploads something to the site, the Script download reports an updated feed page.

I saw something called COMET. Although reading articles / textbooks confused me even more.

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

+4
source share
1 answer

On the server side, you'll need a script that can determine if there is new content (for example: new files) based on a timestamp (for example: last request). On the client side, you have two options:

Poll aka Periodic Update :

This basically means that your client polled the server at intervals to check if there is any new data. You want your questions and answers as easy as possible. It can also help if you run the script processing these requests in a separate process.

You will need to adjust the interval to one that is suitable for both the server and the user. You can also use Heartbeat to indicate whether the user is active or not, so you can stop polling the server if the user left the window open but disconnected from the computer.

HTTP Streaming aka "Comet" :

This will require one more setting; but this is basically a long-term connection from the client to the server, and the server can โ€œclickโ€ the content on the client if necessary.

+3
source

All Articles