Jump to content

real time reporting


deansatch

Recommended Posts

If I have entries in a mysql db and I want to display the most recent entry on a web page in real time, how would I go about this? Would I have to write a script that queries the database every couple of seconds? Or is there a way to get the database to communicate with a script so that it only gets queried when there is a new entry?

 

I am just thinking about the best way of not overusing the server by checking every 1-2 seconds. Something a bit like a forum "users currently online are: etc.." but up to date within a few seconds.

Link to comment
https://forums.phpfreaks.com/topic/180537-real-time-reporting/
Share on other sites

I know it will involve ajax which is fine...the part I am unsure about is the fact that my ajax script will be using a php script to query the database every couple of seconds - which I assume will not be a good thing if I get a lot of traffic and have a big database. I'm wondering what is the best, least server intensive way of checking for new db entries and then return the results only if there is a new result to return.

Link to comment
https://forums.phpfreaks.com/topic/180537-real-time-reporting/#findComment-952672
Share on other sites

Well the query should be a simple one, the only way i can think of would be to setup a cache, so for example

 

User 1: Ajax requests update

System: looks at cache file and checks the modified time, if its over 5 seconds then query database and update file, return results

User 2: Ajax requests update (1 second later)

System: looks at cache file and checks the modified time, and its under 5 seconds get results from file return results.

 

etc etc

but either way if you get "a lot of traffic" (depends what you mean by a lot) and are hitting the server every few seconds then its going to use some resource, memory/bandwidth/a service/disc

so it really depends on your server.

Link to comment
https://forums.phpfreaks.com/topic/180537-real-time-reporting/#findComment-952683
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.