-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.php
53 lines (43 loc) · 1.54 KB
/
server.php
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
<?php
use App\Http\Kernel as HttpKernel;
use App\Websocket\Kernel as WSKernel;
use Dotenv\Dotenv;
use RTC\Server\Server;
use RTC\Watcher\Watcher;
require __DIR__ . '/vendor/autoload.php';
$env = Dotenv::createImmutable(__DIR__)->load();
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'])
);
$server
->setDocumentRoot(__DIR__ . '/public')
->setPidFile(__DIR__ . '/.pid')
->setHttpKernel(HttpKernel::class)
->setWebsocketKernel(WSKernel::class)
->onStart(function (\Swoole\Http\Server $server) use ($env) {
// Monitor filesystem changes for hot code reloading
if ('development' == strtolower(strval($env['APP_ENV']))) {
Watcher::create()
->addPath(__DIR__ . '/app')
->addPath(__DIR__ . '/routes')
->addPath(__DIR__ . '/vendor')
->onChange(fn() => $server->reload())
->start();
}
echo "Server started at http://$server->host:$server->port\n";
});
$server->setLogOption(
filePath: __DIR__ . '/storage/logs/phprtc.log',
);
if ('true' == $env['SERVER_DAEMONIZE']) {
$server->daemonize();
}
$server->run();
} catch (Throwable $e) {
console()->error($e);
}