Any idea how the "Spy" feature of Dp works? Whenever thread is made I believe data goes into the database and the spy script fetches it, but HOW? OF course AJAX...and I quite know AJAX but still how can the script know a new db value has been added?
I haven't heard about SPY feature, but I am so curious on what it could do . Could you explain a bit about it? Plz. Thanks.
You can get the last thread, after that every x seconds check if there's a new thread created. Every thread has a unique id in the table, so you can easily get this info.
hmm again and again checking wouldn't cause much load? Is it possible that server sends data to the script, telling its updated!
See I know how it is working, whenever a new post is made, the new post "informs" the spy feature that "i am made " (lol), how do I do that? Instead of checking the DB every second...
This is a whole matter by itself. I don't know how this work actually, but this is my thought. You get good idea about exhausting database if every user constantly request a new post check directly on database. It would end up on database overloading. However, when taking the reversed approach, whenever database is updated, you want to inform current users. This is virtually impossible. Server cannot send information to web browsers without being requested first. There are couple ways to work around the problem. My guess is caching. Whenever database is updated, a new cache is made. And users' web browser would implement ajax to compare the cache with current copy in browsers. It would save database from over working.
@zandigo You are saying what pretty much I am planning, SYNCHRONIZE the data from time to time. but the question si how to do it effectively without much load on server? PS: Can any DP admin clarify how it is done? Thanks!
Well, I have explained one way to reduce work on server. Caching. It's different from directly connect to database, and thus, give more advantages besides that. Sorry, you are not asking me but I'm just saying anyway .
I think it's done this way: Spy script is refreshed every second or so. It probably doesn't fetch data from the main post database, but for spy script purpose, every time post is created in main post tables, that post is duplicated (short/spy version) in temporary post table. Since only last 25 or whatever posts are shown in spy, that temp table will not use much space and will be fast, responsive. I'm not sure about caching, since you need really fresh data for spy.. maybe some minimal caching of minute or less (I haven't checked how up to date spy feed is). It must have some load since it's often refreshed, but when done this way it's acceptable load. Digg has the same thing I believe.
er, refreshing every second is stupid. the most effective way of doing the notify (just as you do chats on facebook or on-site support etc) is to use comet - which is javascript server push (similar to how you'd do multipart progressive jpgs via PHP, also can be populated through PHP). the principle is simple - it may load a javascript file which remains open as a stream and as soon as a new post appears, it gets the new data instantly / fires an event / runs a js function that does something, use your imagination. FAR more effective than 10000 users doing ajax calls every second... google it, it's REALLY very handy but needs a special module built into mod_proxy for apache - it also works as a standalone daemon with its own port. an example solution for comet is APE: http://www.ape-project.org/en/demos/APE_real_time_chat.html but google for 'javascript comet' etc, i know/use ape because it has a mootools interface.
It seems it requested data per 5 seconds, then it stores the new entries in array and push it one by one to the display in every 1 second or so...
i stand corrected. this really does use ajax every 5 seconds - had not seen it before and just assumed. still, does not make my post about comet any less valid
The comet is cool indeed... I have read it before but never get it worked, however, now I finally can get the working example... I think I will use it in my future project... And yes, the comet should do better than requesting data frequently...