title: PHP Fatal error: Uncaught Error: Class 'Drupal\module_name\WebSocketServer' not found in D:\"path\to\script"
body: <p>I'm working on a WebSocket implementation using Php's Ratchet library in a Drupal Project.</p>
  <p>Everything works if I initialize the WebSocket class in the same file as the one where it is defined (WebSocketServer.php).
  However, if I try to move the inizialization logic to another file (start_socket.php), which would be nice to keep the project organized, and then import the class WebSocketServer by using <code>namespace</code> and <code>use</code> keywords, I get the following error when executing <code>php start_socket.php</code>:</p>
  <p><em>PHP Fatal error:  Uncaught Error: Class 'Drupal\module_name\WebSocketServer' not found in D:\PROYECTOS_Y_EDICION\Programming\project_name\project_name\modules\custom\module_name\src\start_socket.php:15
  Stack trace:
  #0 {main}
  thrown in D:\PROYECTOS_Y_EDICION\Programming\project_name\project_name\modules\custom\module_name\src\start_socket.php on line 15</em></p>
  <p>Here is the beginning of the WebSocketServer file:</p>
  <pre><code>&lt;?php
  namespace Drupal\module_name;
  
  use Ratchet\MessageComponentInterface;
  use Ratchet\ConnectionInterface;
  require_once '../../../../vendor/autoload.php';
  
  class WebSocketServer implements MessageComponentInterface {
  </code></pre>
  <p>and here is the start_socket.php file:</p>
  <pre><code>&lt;?php
  
  namespace Drupal\module_name;
  
  set_time_limit(0);
  
  use Ratchet\Server\IoServer;
  use Ratchet\Http\HttpServer;
  use Ratchet\WebSocket\WsServer;
  use WebSocketServer;
  require_once '../../../../vendor/autoload.php';
  
  
  $server = IoServer::factory(
    new HttpServer(new WsServer(new WebSocketServer())),
    8085
  );
  $server-&gt;run();
  </code></pre>
  <p>I have tried importing the class with <code>require_once</code> instead of <code>namespace</code> and <code>use</code>, as follows:</p>
  <pre><code>&lt;?php
  
  set_time_limit(0);
  
  require_once '../../../../vendor/cboden/ratchet/src/Ratchet/Server/IoServer.php';
  require_once '../../../../vendor/cboden/ratchet/src/Ratchet/Http/HttpServer.php';
  require_once '../../../../vendor/cboden/ratchet/src/Ratchet/Http/CloseResponseTrait.php';
  require_once '../../../../vendor/cboden/ratchet/src/Ratchet/WebSocket/WsServer.php';
  require_once 'WebSocketServer.php';
  require_once '../../../../vendor/autoload.php';
  
  
  $server = IoServer::factory(
    new HttpServer(new WsServer(new WebSocketServer())),
    8085
  );
  $server-&gt;run();
  </code></pre>
  <p>but that gives me the following error:</p>
  <p><em>PHP Fatal error:  Trait 'Ratchet\Http\CloseResponseTrait' not found in D:\PROYECTOS_Y_EDICION\Programming\project_name\project_name\vendor\cboden\ratchet\src\Ratchet\Http\HttpServer.php on line</em></p>
  <p>The directory tree for the Drupal module is the following:</p>
  <pre><code>module_name/
  -----------src/
  --------------start_socket.php
  --------------WebSocketServer.php
  </code></pre>
  <p>Any idea of why I'm getting these errors?</p>