Is there a way to find out which articles / nodes are currently being read? I am Not looking for a module (although finding one might be inspirational), but for the MySQL code to do this. The idea is to provide a small block with, for instance, 5 other articles being read while a visitor (mainly anonymous ones) is reading a particular node, so something like "Currently also being read: node a, g, t, f and q".
Can this be done in Drupal/PHP code?

Comments

roulaa6’s picture

I'm not sure if there's a module that does this but if you want to create your own code then you have to create a simple new module try this in your module:

function yourcontenttype_node_view($node, $view_mode) {
  if ($view_mode == 'full') {
     //Your php code goes here
  }
}
modul’s picture

Thanks, Roulaa6, but my question actually had to do with the "//Your php code goes here" part :-) . I know how to implement what I'm looking for, but I am trying to figure out the code required to find out "which other articles are currently being read" (also, or even mainly, by anonymous visitors). BTW, I am using Drupal 6.x. And it should be done in PHP code. I can add that to a node or a block, but I do not have access to the Drupal server itself, i.e. I cannot install a new module.

modul’s picture

Could anyone help me here? I'm looking for the MySQL / PHP code which shows me (probably in a block) which Other articles are being read while a visitor is reading something. So, something like "At this moment, also nodes 123, 321 and 765 are being read".
Maybe that code should look for all nodes which have been opened between, say, "Current Time, and Current time minus 5 minutes" or so?
Any ideas?

ayesh’s picture

Once Drupal generate the requested page and send it to the browser, Drupal don't keep the connection live. So there is no good way to find who has open threads(process threads).

However, with Statistics module you have "hot" data about who read the node, when and which node.

Raw data could like this.
User 0 - node/5 - some UNIX datastamp.

With Views or some stuff, you can try to group thaw data to some actual information and count it.

E.x.
When a user is viewing node/5, we run a View to get list of hits to the node id=5 and hit time was 5 minutes ago(assuming user read it 5 minutes. We have no way to know if the user is away or not without magical javascripts or Ajax).
And finallycount them.

modul’s picture

Thanks for your input, Ayesh. I'll see if I can get it to work.