0

Usually I make content refresh automatically with the javascript function using setInterval. But it seems ineffective because every second the content must be reloaded will take up a lot of resources.

Therefore if there is another alternative to creating an automatic refresh function only when the data has changed in the database.

Nay
  • 27
  • 5
  • Integrate `websocket` in php and listen for changes in `javascript` and refresh on changes Ref: [Websockets in PHP](https://stackoverflow.com/questions/14512182/how-to-create-websockets-server-in-php) – Sameer Jun 19 '20 at 02:57
  • Thank you for your alternative solution. Maybe i am newbie :( need an example simple project which is integrated with the mysql database. – Nay Jun 19 '20 at 03:10
  • If the resources are at the database layer, include `SHOW CREATE TABLE {tablename}` and the SQL to retrieve it. What would the SQL be to retrieve the changes? How are database changes occuring and could you use a websocket to pipe raw new results from whatever changes it. – danblack Jun 19 '20 at 04:08

1 Answers1

1

One way to update your data would be to use Ajax in the frontend to request the data every few seconds and update it instead of reloading the page. Otherwise, you should check out socket.io (websockets)

Rohan Mukherjee
  • 280
  • 2
  • 7