-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebsocket.php
More file actions
33 lines (27 loc) · 774 Bytes
/
websocket.php
File metadata and controls
33 lines (27 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
use Backend\Infrastructure\ControllerWebSocket;
use Ratchet\Http\HttpServer;
use Ratchet\Server\IoServer;
use Ratchet\WebSocket\WsServer;
use Dotenv\Dotenv;
const ROOT_DIR = __DIR__;
require(ROOT_DIR . '/vendor/autoload.php');
require(ROOT_DIR . '/src/Router.php');
# Load environment variables
$dotenv = Dotenv::createImmutable(ROOT_DIR);
$dotenv->load();
# Error for missing PORT environment variable
if (!isset($_ENV['PORT'])) {
throw new Exception('PORT environment variable is missing');
}
# Instance websocket server
$server = IoServer::factory(
new HttpServer(
new WsServer(
new ControllerWebSocket($router)
)
),
$_ENV['PORT']
);
echo "Server running at ws://localhost:" . $_ENV['PORT'] . "\n";
$server->run();