Quick help needed

Discussion in 'PHP' started by quickcash, Jul 25, 2009.

  1. #1
    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?
     
    quickcash, Jul 25, 2009 IP
  2. zandigo

    zandigo Greenhorn

    Messages:
    71
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #2
    I haven't heard about SPY feature, but I am so curious on what it could do :D. Could you explain a bit about it? Plz. Thanks.
     
    zandigo, Jul 26, 2009 IP
  3. goscript

    goscript Prominent Member

    Messages:
    2,753
    Likes Received:
    306
    Best Answers:
    0
    Trophy Points:
    315
    #3
    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.
     
    goscript, Jul 26, 2009 IP
  4. quickcash

    quickcash Peon

    Messages:
    112
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    hmm again and again checking wouldn't cause much load? Is it possible that server sends data to the script, telling its updated!
     
    quickcash, Jul 26, 2009 IP
  5. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #5
    It's just simple ajax with using timestamp as reference to the browser. I may be wrong though.
     
    Kaizoku, Jul 26, 2009 IP
  6. quickcash

    quickcash Peon

    Messages:
    112
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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...
     
    quickcash, Jul 27, 2009 IP
  7. zandigo

    zandigo Greenhorn

    Messages:
    71
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #7
    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, Jul 27, 2009 IP
  8. quickcash

    quickcash Peon

    Messages:
    112
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    @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!
     
    quickcash, Jul 27, 2009 IP
  9. zandigo

    zandigo Greenhorn

    Messages:
    71
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #9
    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 :D.
     
    zandigo, Jul 27, 2009 IP
  10. umpahpah

    umpahpah Well-Known Member

    Messages:
    266
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #10
    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.
     
    umpahpah, Jul 29, 2009 IP
  11. HappyBoy

    HappyBoy Peon

    Messages:
    523
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #11
    I am wondering why DP needs "SPY script"?? Can someone shed some light?
     
    HappyBoy, Jul 30, 2009 IP
  12. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #12
    Because they like to spy on little kids.
     
    Kaizoku, Jul 30, 2009 IP
  13. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #13
    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.
     
    dimitar christoff, Jul 30, 2009 IP
  14. keaglez

    keaglez Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    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...
     
    keaglez, Jul 30, 2009 IP
  15. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #15
    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 :)
     
    dimitar christoff, Jul 30, 2009 IP
  16. keaglez

    keaglez Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #16
    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...
     
    keaglez, Jul 30, 2009 IP
  17. quickcash

    quickcash Peon

    Messages:
    112
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #17
    Thanks for the help guys I'll give javascript comet a shot! :)
     
    quickcash, Jul 30, 2009 IP