Loading pages with dynamic content

I've been working on a project for a couple of Minecraft servers that use Bukkit. I'm trying to create a web page that contains a dynamic map of the servers' worlds, as well as a real-time event update system, where a <div> is updated as events happen on the server. To give a brief outline of how my system works, the Minecraft servers communicate events with a Node.js webserver over the same network via UDP packets, and the Node.js webserver uses these packets to build JavaScript objects containing the event info. The objects are then stored, and passed to Jade whenever the page is requested. Jade takes care of the templating.

What I want to do is update this page dynamically, so that the user doesn't have to refresh the entire page to update the list of events. What I'm trying to implement is something like the Facebook ticker, which updates every time a Facebook friend does something like posting a status, commenting on a post, or 'liking' a post.

In reading this question on SO, I've concluded that I need to use long polling in a PHP script, but I'm not sure of how to integrate PHP with a webserver written almost entirely in Node.js. How could I go about doing this?


EDIT:
I've run into a problem in the clientside code.

This is the script block:

script(src='/scripts/jadeTemplate.js')
script(src='/socket.io/socket.io.js')
script(type='text/javascript')
  var socket = io.connect();
  socket.on('obj', function(obj) {
    var newsItem = document.createElement("item");
    jade.render(newsItem, 'objTemplate', { object: obj });
    $('#newsfeed').prepend(newsItem);
    console.log(obj);
    alert(obj);
  });

And this is objTemplate.jade:

p #{object}
// That's it.

When the alert() and console.log() are placed at the top of the script, it alerts and logs, but at the bottom, they don't execute (hence, I think it's a problem with either the creation of newsItem, the jade.render(), or the prepend.

If I need to provide any more snippets or files let me know. I'm still tinkering, so I might solve it on my own, but unless I update, I still need help. :)

I'd skip PHP and take a look at socket.io. It uses websockets when possible, but it will fall back to long-polling when necessary, and the client side library is very easy to use.

Whenever your node.js server has a new object ready to go, it will push it to all connected browsers. Use ClientJade to render the object using your template (you may have to break out the relevant part of the main template into its own file), then prepend the generated dom element to your feed.

First, if it isn't this way already, you'll need to break out the relevant part of your jade template into its own file. Call it objTemplate.jade. Then use ClientJade to create a compiled template that can be run in the browser: clientjade objTemplate.jade > jadeTemplate.js. Put jadeTemplate.js in your public js directory.

In your node.js app, you'll have something like this (pseudo-codey):

var io = require('socket.io').listen(httpServer);

listenForUDPPackets(function(obj) {
    saveObjSomewhere(obj);
    io.sockets.emit('obj', obj);
});

Then on the client, something like this:

<script src="/js/jadeTemplate.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
    var socket = io.connect();
    socket.on('obj', function(obj) {
        var newsItem = document.createElement();
        jade.render(newsItem, 'objTemplate', obj);
        $('#newsFeed').prepend(newsItem);
    });
</script>