Take the 2-minute tour ×

I intend to create a web interface to display data from a database in real-time. The data comes from monitoring devices and is then stored into the database by a software component independent from mining and I can access neither its configuration file nor its source code. I intend to use Ajax/PHP to display the data on the web interface and as I think I will have both JavaScript and HTML and PHP in the same piece of code, I thought design patterns may help.

Do you have any implementation idea on how I could have the new records and all updates displayed in the website without refreshing the page and in real time? Which design pattern could help (either on the server side or on the client side)? Could it be useful to use the observer pattern to observe a PDO?

NB: I've just had some JavaScript Ajax courses and I only have theoretical knowledge of the design patterns, but I'm familiar with OOP.

share|improve this question
This is bordering on belonging on programmers.stackexchange.com –  DaveRandom Apr 24 '12 at 16:30
Hey @inkredibly, did you find a solution to this problem? –  SLearner Aug 23 '13 at 13:15
add comment

1 Answer

Best way would be to use JQuery to check a php script every few seconds and then fresh a div

Place that in between your head tags

<script type="text/javascript">
var auto_refresh = setInterval(
function ()
}, 10000); // refresh every 10000 milliseconds


place in main body(every new updates will be displayed in that div)

<div id="load_updates"> </div>

your php file could look like this, ever thing that is echoed out will be appear in the div in you main page. You can run queries then echo the data.


echo "Testing ......";

share|improve this answer
Thank you for your answer. I see your point, but the problem is that with this we have to send queries, run scripts on the serverside sometimes when there are no updates. I want something on the serverside that say hello there are new records..... –  Inkredibly Apr 24 '12 at 17:24
jQuery is not always necessary, it is only one from a really wide range of possibilities. But the worst part in your "solution" is actually a statement that this is "best" method. The second problem is that you actually make OP believe he/she needs to execute whole page and every 10 seconds instead of suggesting more lightweight (response smaller in size, executing only necessary checks on the server) and closer to real time (less impact, so more frequent updates are possible). You do not event mention Comet. The question was serious, response is not. –  Tadeck May 23 '12 at 6:10
add comment

Your Answer


