File: server-socket.php

Recommend this page to a friend!
  Classes of Ahmad Mustapha  >  ReactPHP Chat Client  >  server-socket.php  >  Download  
File: server-socket.php
Role: Example script
Content type: text/plain
Description: Example script
Class: ReactPHP Chat Client
Implement a live chat system based on Web Sockets
Author: By
Last change:
Date: 3 months ago
Size: 1,075 bytes
 

 

Contents

Class file image Download
<?php

use App\Socket\Server;
use
App\Core\Colis\Colis;
use
Ratchet\Http\HttpServer;
use
Ratchet\Server\IoServer;
use
Ratchet\WebSocket\WsServer;

set_exception_handler(function ($exception) {
   
$file = __DIR__ . '/storage/logs/' . time() . '.log';
   
$log = json_encode([
       
'message' => $exception->getMessage(),
       
'file' => $exception->getFile(),
       
'line' => $exception->getLine(),
       
'code' => $exception->getCode(),
    ],
JSON_PRETTY_PRINT);
   
file_put_contents($file, $log);
    echo
"\n[*] Error: {$exception->getMessage()} => {$exception->getFile()} @ Line {$exception->getLine()}\n";
});

require
'vendor/autoload.php';
require
'colis.php';

$port = 10000;
$colis = Colis::getListeners();

$server = new Server($colis);
$IoServer = IoServer::factory(
    new
HttpServer(
        new
WsServer($server)
    ),
   
$port
);

setLoop($IoServer->loop);

require
'app/Core/Helpers/socketHelperFunctions.php';
require
'app/Core/event-listeners.php';

echo
"\n[*] Socket-Server running on port {$port}\n";

$server->init($argv);
$IoServer->run();


For more information send a message to info at phpclasses dot org.