Jump to content

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

Technically if your page is dynamically build it will be "real time" but I assume you mean without the user needing to refresh the page to get the new data, in that case your need to (as jonsjava stated) look at ajax (recommened) or an iframe..

 

Link to comment
https://forums.phpfreaks.com/topic/180537-real-time-reporting/#findComment-952662
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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.