Skip to content

Commit ff6a140

Browse files
committed
add multi-thread support
1 parent 58e0b75 commit ff6a140

File tree

5 files changed

+29
-19
lines changed

5 files changed

+29
-19
lines changed

composer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717
"require": {
1818
"php": "^7.4|^8.0",
1919
"ext-json": "*",
20-
"antidot-fw/react-framework": "^1.0.3",
21-
"antidot-fw/fast-router-adapter": "^0.1.0",
20+
"antidot-fw/react-framework": "^1.1.0",
21+
"antidot-fw/antidot-react-psr15": "^0.0.1",
22+
"antidot-fw/fast-router-adapter": "^0.2.0",
2223
"antidot-fw/cli": "^1.1.0",
2324
"antidot-fw/container": "^0.1.0",
2425
"antidot-fw/dev-tools": "^0.1.2",
2526
"antidot-fw/event-dispatcher": "^2.0.3",
26-
"antidot-fw/framework": "^0.1.1",
27+
"antidot-fw/framework": "^0.2.0",
2728
"antidot-fw/logger": "^1.1.0",
2829
"antidot-fw/symfony-config-translator": "^1.1.0",
2930
"antidot-fw/yaml-config-provider": "^0.1.0",
@@ -66,7 +67,7 @@
6667
"sort-packages": true
6768
},
6869
"extra": {
69-
"zf": {
70+
"laminas": {
7071
"component-whitelist": [
7172
"antidot-fw/framework",
7273
"antidot-fw/logger",

config/config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
];
1616

1717
$aggregator = new ConfigAggregator([
18+
\Antidot\React\PSR15\Container\Config\ConfigProvider::class,
1819
\WShafer\PSR11MonoLog\ConfigProvider::class,
1920
\Antidot\Event\Container\Config\ConfigProvider::class,
2021
\Antidot\Logger\Container\Config\ConfigProvider::class,

config/services/dependencies.prod.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ parameters:
2727
stream: 'var/log/%date%-default.log'
2828
level: 400
2929
server:
30-
max_concurrency: 2048
31-
workers: 16
30+
max_concurrency: 512
31+
buffer_size: 2097152
32+
workers: 4

public/index.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,27 @@
1717
$application = $container->get(Application::class);
1818
(require 'router/middleware.php')($application, $container);
1919
(require 'router/routes.php')($application, $container);
20+
$globalConfig = $container->get('config');
21+
$serverConfig = $globalConfig['server'];
2022

2123
$loop = $container->get(LoopInterface::class);
22-
Child::fork(
23-
shell_exec('nproc') ? (int)shell_exec('nproc') : 16,
24-
static function () use ($container) {
25-
$server = $container->get(Server::class);
26-
$server->on('error', static function ($err) use ($container) {
27-
$logger = $container->get(LoggerInterface::class);
28-
$logger->critical($err);
29-
});
30-
31-
$socket = $container->get(Socket::class);
32-
$server->listen($socket);
24+
$serverInstance = static function () use ($container) {
25+
$server = $container->get(Server::class);
26+
$server->on('error', static function ($err) use ($container) {
27+
$logger = $container->get(LoggerInterface::class);
28+
$logger->critical($err);
3329
});
3430

31+
$socket = $container->get(Socket::class);
32+
$server->listen($socket);
33+
};
34+
35+
if (1 < $serverConfig['workers']) {
36+
Child::fork($serverConfig['workers'], $serverInstance);
37+
} else {
38+
$serverInstance();
39+
}
40+
41+
3542
$loop->run();
3643
});

router/middleware.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
return static function (Application $app): void {
1313
$app->pipe(ErrorMiddleware::class);
14-
// $app->pipe(ExceptionLoggerMiddleware::class);
15-
// $app->pipe(RequestLoggerMiddleware::class);
14+
$app->pipe(ExceptionLoggerMiddleware::class);
15+
$app->pipe(RequestLoggerMiddleware::class);
1616
$app->pipe(RouteDispatcherMiddleware::class);
1717
$app->pipe(RouteNotFoundMiddleware::class);
1818
};

0 commit comments

Comments
 (0)