title: Ratchet basic chat application giving error "Failed opening required"
body: <p>I'm trying out the Ratchet library to use WebSockets located at <a href="http://socketo.me/" rel="noreferrer">http://socketo.me/</a> but am experiencing some problems when running the server script from the command line in Ubuntu.</p>
  
  <p>After successfully installing composer and Ratchet I'm following the tutorial for a basic chat application at <a href="http://socketo.me/docs/hello-world" rel="noreferrer">http://socketo.me/docs/hello-world</a> and I'm at the Running It step. My file structure, with websockets being my project folder, is:</p>
  
  <pre><code>kingsconflict
     websockets
        chat.php
        chat-server.php
        composer.json
        vendor
           autoload.php
           (dependecies included by composer for Ratchet)
  </code></pre>
  
  <p>The error I get when typing "sudo php chat-server.php" is "PHP Fatal error:  require(): Failed opening required '/var/www/kingsconflict/vendor/autoload.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/kingsconflict/websockets/chat-server.php on line 5". It seems like it's trying to open /var/www/kingsconflict/vendor/autoload.php but the actual path is /var/www/kingsconflict/websockets/vendor/autoload.php, and I'm not sure why it's doing this.</p>
  
  <p><strong>chat-server.php</strong></p>
  
  <pre><code>&lt;?php
  use Ratchet\Server\IoServer;
  use MyApp\Chat;
  
      require dirname(__DIR__) . '/vendor/autoload.php';    // Error here
  
      $server = IoServer::factory(
          new Chat()
        , 8080
      );
  
      $server-&gt;run();
  </code></pre>
  
  <p>I tried subbing the errored line with the line below, and I stop getting the error but I get a new error "PHP Fatal error:  Class 'MyApp\Chat' not found" which leads me to believe this fix isn't right.</p>
  
  <pre><code>require ('./vendor/autoload.php');
  </code></pre>
  
  <p>The code for the other files are the same as shown in the Ratchet tutorial, but just in case I'll post them below</p>
  
  <p><strong>chat.php</strong></p>
  
  <pre><code>&lt;?php
  namespace MyApp;
  use Ratchet\MessageComponentInterface;
  use Ratchet\ConnectionInterface;
  
  class Chat implements MessageComponentInterface {
      protected $clients;
  
      public function __construct() {
          $this-&gt;clients = new \SplObjectStorage;
      }
  
      public function onOpen(ConnectionInterface $conn) {
          // Store the new connection to send messages to later
          $this-&gt;clients-&gt;attach($conn);
  
          echo "New connection! ({$conn-&gt;resourceId})\n";
      }
  
      public function onMessage(ConnectionInterface $from, $msg) {
          $numRecv = count($this-&gt;clients) - 1;
          echo sprintf('Connection %d sending message "%s" to %d other connection%s' . "\n"
              , $from-&gt;resourceId, $msg, $numRecv, $numRecv == 1 ? '' : 's');
  
          foreach ($this-&gt;clients as $client) {
              if ($from !== $client) {
                  // The sender is not the receiver, send to each client connected
                  $client-&gt;send($msg);
              }
          }
      }
  
      public function onClose(ConnectionInterface $conn) {
          // The connection is closed, remove it, as we can no longer send it messages
          $this-&gt;clients-&gt;detach($conn);
  
          echo "Connection {$conn-&gt;resourceId} has disconnected\n";
      }
  
      public function onError(ConnectionInterface $conn, \Exception $e) {
          echo "An error has occurred: {$e-&gt;getMessage()}\n";
  
          $conn-&gt;close();
      }
  }
  </code></pre>
  
  <p><strong>composer.json</strong></p>
  
  <pre><code>{
      "autoload": {
          "psr-0": {
              "MyApp": "src"
          }
      },
      "require": {
          "cboden/Ratchet": "0.2.*"
      }
  }
  </code></pre>
  
  <p><strong>autoload.php</strong> (Didn't edit this but what the hell)</p>
  
  <pre><code>&lt;?php
  
  // autoload.php generated by Composer
  
  require_once __DIR__ . '/composer' . '/autoload_real.php';
  
  return ComposerAutoloaderInit0964ef3a5e66723368300f04c3206ca1::getLoader();
  </code></pre>