-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.php
More file actions
39 lines (29 loc) · 912 Bytes
/
server.php
File metadata and controls
39 lines (29 loc) · 912 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
34
35
36
37
38
39
#!/usr/bin/env php
<?php
declare(strict_types=1);
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
require __DIR__ . '/vendor/autoload.php';
}
use DI\Container;
use Swoole\Http\Server;
use Twilight\Infrastructure\HTTP\Kernel;
$server = new Server('0.0.0.0', 9501);
$container = new Container();
$configure = require __DIR__ . '/config/container.php';
$configure($container);
$kernel = Kernel::create($container);
$server->set(array(
'worker_num' => 1,
'task_worker_num' => 5,
));
$server->on('start', static function () {
echo "Twilight is started at http://0.0.0.0:9501\n";
});
$server->on('request', $kernel);
$server->on('task', function (Server $server, $taskId, $workerId, $data) {
$server->finish($data);
});
$server->on('finish', function ($server, $taskId, $data) {
echo "Task $taskId finished:", json_encode($data, JSON_THROW_ON_ERROR), "\n";
});
$server->start();