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:
<?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->run();
And here's my messages controller that loads the view:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Messages extends CI_Controller {
function index()
{
$this->load->view( 'includes' );
$this->load->view( 'messages_view' );
}
}