title: How to inform a NodeJS server of something using PHP?
body: <p>I'd like to add a live functionality to a PHP based forum - new posts would be automatically shown to users as soon as they are created.</p>
  
  <p>What I find a bit confusing is the interaction between the PHP code and NodeJS+socket.io.</p>
  
  <p>How would I go about informing the NodeJS server about new posts and have the server inform the clients that are watching the thread in which the post was posted?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Tried the following code, and it seems to work, my only question is whether this is considered a good solution, as it looks kind of messy to me.</p>
  
  <p>I use socket.io to listen on port 81 to clients, and the server running om port 82 is only intended to be used by the forum - when a new post is created, a PHP script sends a POST request to localhost on port 82, along with the data.</p>
  
  <p>Is this ok?</p>
  
  <pre><code>var io = require('socket.io').listen(81);
  
  io.sockets.on('connection', function(socket) {
      socket.on('init', function(threadid) {
          socket.join(threadid);
      });
  });
  
  var forumserver = require('http').createServer(function(req, res) {
      if (res.socket.remoteAddress == '127.0.0.1' &amp;&amp; req.method == 'POST') {
          req.on('data', function(chunk) {
              data = JSON.parse(chunk.toString());
              io.sockets.in(data.threadid).emit('new-post', data.content);
          });
      }
  
      res.end();
  }).listen(82);
  </code></pre>