Automatically run PHP server on page load without terminal (NO AJAX) in Codeigniter
<p>I'm working on a chat system using Ratchet websockets. It's necessary to start the server from the terminal command "php " but I need to let this happen automatically when a user opens the chat page. I tried exec(), shell_exec() and system() but the problem is that my chat-server.php file does not return a message, it just starts the server causing the localhost to keep loading.
Here's the chat-server.php file:</p>

<pre><code>&lt;?php
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use MyApp\Chat;

require dirname(__DIR__) . '/vendor/autoload.php';

$server = IoServer::factory(
    new HttpServer(
        new WsServer(
            new Chat()
        )
    ),
    8080
);
$server-&gt;run();
</code></pre>

<p>And here's my messages controller that loads the view:</p>

<pre><code>    &lt;?php
    defined('BASEPATH') OR exit('No direct script access allowed');

    class Messages extends CI_Controller {  

    function index()
    {
        $this-&gt;load-&gt;view( 'includes' );
        $this-&gt;load-&gt;view( 'messages_view' );
    }
}
</code></pre>