0

I'm trying to make a web countdown timer. I use a .txt file where I can put deadlines in. The webapp reads this, and forms the countdowns on the screen.

My problem is the following:

The plan is that I can change deadlines in the txt file during the time that the app is working. This is possible, using an auto refresh on my page. But this gives a flicker with every refresh.

I was now wondering if there's an other, and better way to do this. I was thinking to execute the read function every second, instead of refreshing, but I don't think it can work like this, because it's in PHP.

halfer
  • 19,824
  • 17
  • 99
  • 186

2 Answers2

0

If you want your page to update after it has loaded, try using some client-side javascript. You can always have the javascript make a web request to your PHP server and update the page if the value has changed. This doesn't reload the page so you won't see the "flicker"

Lorna Mitchell
  • 1,819
  • 13
  • 22
  • This sounds good indeed, can you give me some more info, or a way to search for it? tutorial for example? thanks! – pieter-jan goeman Mar 02 '17 at 16:00
  • Search terms: try "ajax update tutorial", I think you want this https://www.w3schools.com/php/php_ajax_php.asp or something like it, showing you how to use Javascript after your PHP has created the page. – Lorna Mitchell Mar 16 '17 at 09:23
0

You can either use a push or pull approach:

The pull approach would be, what Lorna Mitchell. So you would fire up a ajax request every x minutes/seconds and that way ask the server for changes.

The push approach means, that the servers sends the changes directly to the client, without the necessity of the client to do a request. This is done by using sockets (e.g. http://websocket.org/).

Tek
  • 489
  • 3
  • 13