Welcome Guest, Not a member yet? Register   Sign In
Start ratchet web server in codeginiter


What is correct way to start ratchet web socket server in codeigniter?
I tried Events.php file and events pre_system an post_system, but codeigniter becomes unresponsive

My Code

$SocketServer = null;

Events::on('post_system'function () {

    $SocketServer = IoServer::factory(
        new HttpServer(
            new WsServer(
                new \ServerEvents\Chat\Chat()


IoServer can't be run within a PHP-website, you need to start it as a service*, please read their documentation.

* from the command line.

Thank you

Is there any library that enables websocket functionality in codeigniter? Could you recommend the one?

I have never developed a websocket in PHP. If we take one step back, how did you start the websocket after you have put that code into CodeIgniter?


(late but because i found this thread when i do a chat, perhaps it is gonna help others)

as @jreklund said the webSocket server is independant and must be run as a service from the command line. The goal is to use codeIgniter in the websocket server and not the socket server in codeIgniter

to access codeIgniter functionalities from the socket server, what i did is partially copying the index.php of the public folder of codeIgniter.
The idea is : Load the app but do not run it and then you can access all the helpers then Libraries, Models & Entities .

Controllers are made to work with the incoming request, so i think we should not try to call codeigniter's controllers from another PHP script.

i called this file codeigniter.php :

PHP Code:

// Path to the front controller (this file)

 * This process sets up the path constants, loads and registers
 * our autoloader, along with Composer's, loads our constants
 * and fires up an environment-specific bootstrapping.

// Ensure the current directory is pointing to the front controller's directory

// Load our paths config file
// This is the line that might need to be changed, depending on your folder structure.
$pathsConfig FCPATH '../../codeigniter4/app/Config/Paths.php';
// ^^^ Change this if you move your application folder
require realpath($pathsConfig) ?: $pathsConfig;

$paths = new Config\Paths();

// Location of the framework bootstrap file.
$bootstrap rtrim($paths->systemDirectory'\\/ ') . DIRECTORY_SEPARATOR 'bootstrap.php';
$app      = require realpath($bootstrap) ?: $bootstrap;

 * the tools are loaded that's enough.
// $app->run(); 

and then in the code of the webSocket server (or whatever) :

PHP Code:
require "codeigniter.php"

// then you can acces
$service service('myChatLib') ;
$blablaModel model('Blabla') ;
// etc 

Theme © iAndrew 2016 - Forum software by © MyBB