deansatch Posted November 6, 2009 Share Posted November 6, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/180537-real-time-reporting/ Share on other sites More sharing options...
jonsjava Posted November 6, 2009 Share Posted November 6, 2009 This is going to be a javascript/AJAX question. Quote Link to comment https://forums.phpfreaks.com/topic/180537-real-time-reporting/#findComment-952580 Share on other sites More sharing options...
MadTechie Posted November 6, 2009 Share Posted November 6, 2009 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.. Quote Link to comment https://forums.phpfreaks.com/topic/180537-real-time-reporting/#findComment-952662 Share on other sites More sharing options...
deansatch Posted November 6, 2009 Author Share Posted November 6, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/180537-real-time-reporting/#findComment-952672 Share on other sites More sharing options...
MadTechie Posted November 6, 2009 Share Posted November 6, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/180537-real-time-reporting/#findComment-952683 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.