title: Sending and receiving information (from a PHP file) with socket.io
body: <p>So I've spent the day taking tutorials on socket.io and I've found myself completely stuck due to the overwhelmingly low amount of tutorials out there. I would like to use socket.io in order to send a variables to a PHP page and retrieve/display information.</p>
  
  <p>Super simple app.js (socket.io server)</p>
  
  <pre><code>var io = require('socket.io').listen(8000);
  
  io.sockets.on('connection', function (socket) {
    socket.on('message', function () { });
    socket.on('disconnect', function () { });
  });
  </code></pre>
  
  <p>Super simple socket.io index page.</p>
  
  <pre><code> &lt;script&gt;
    var socket = io.connect('http://localhost/');
    socket.on('connect', function () {
      socket.send('hi');
  
      socket.on('message', function (msg) {
        // my msg
      });
    });
  &lt;/script&gt;
  </code></pre>
  
  <p>the php file I want to send the information to...</p>
  
  <pre><code>&lt;?php
  $hostname = 'localhost';
  $username = 'root';
  $password = 'root';
  $database = 'database';
  try {
      $dbh = new PDO("mysql:host=$hostname;dbname=$database", $username, $password);
      $dbh-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
      $stmt = $dbh-&gt;prepare("SELECT * FROM comments WHERE pid = :pid");
      $pid = $_GET['pid'];
      $stmt-&gt;bindParam(':pid', $pid, PDO::PARAM_STR);
      $stmt-&gt;execute();
      $result = $stmt-&gt;fetchAll();
      }
  catch(PDOException $e)
      {
      echo $e-&gt;getMessage();
      }
      $stmt-&gt;execute();
      echo $stmt-&gt;rowCount();
  $dbh = null;
  ?&gt;
  </code></pre>
  
  <p>So essentially all I want to do is use the websocket to send the id of my posts to the PHP page and retrieve the count, automatically updating the count as people vote. Yet I can't find (or figure out) how to accomplish this.</p>
  
  <p>Anyone here familiar with node.js/socket.io that can lend me a hand here?</p>