-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.php
More file actions
56 lines (45 loc) · 1.45 KB
/
server.php
File metadata and controls
56 lines (45 loc) · 1.45 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
use App\Http\Kernel as HttpKernel;
use App\Websocket\Kernel as WSKernel;
use Dotenv\Dotenv;
use RTC\Server\Server;
use Swoole\Runtime;
require __DIR__ . '/vendor/autoload.php';
$env = Dotenv::createImmutable(__DIR__)->load();
Runtime::enableCoroutine();
try {
$server = new Server(
host: strval($env['SERVER_HOST']),
port: intval($env['SERVER_PORT']),
size: intval($env['SERVER_WS_CONNECTION_SIZE']),
heartbeatInterval: intval($env['SERVER_WS_HEARTBEAT_INTERVAL']),
clientTimeout: intval($env['SERVER_WS_CLIENT_TIMEOUT']),
listeners: require __DIR__ . '/config/listeners.php',
);
$server
->setRootDirectory(__DIR__)
->setDocumentRoot(__DIR__ . '/public')
->setPidFile(__DIR__ . '/.pid')
->setHttpKernel(HttpKernel::class);
if ('true' == $env['SERVER_ENABLE_WEBSOCKET']) {
$server->setWebsocketKernel(WSKernel::class);
}
// Monitor filesystem changes for hot code reloading
$server->setHotCodeReload(
status: 'true' == strtolower(strval($env['SERVER_HOT_CODE_RELOAD'])),
paths: [
__DIR__ . '/app',
__DIR__ . '/routes',
__DIR__ . '/vendor'
]
);
$server->setLogOption(
filePath: __DIR__ . '/storage/logs/phprtc.log',
);
if ('true' == $env['SERVER_DAEMONIZE']) {
$server->daemonize();
}
$server->run();
} catch (Throwable $e) {
console()->error($e);
}