chore: 优化docker环境下的启动速度,增加webman进程自动重启来释放内存

This commit is contained in:
xboard
2024-05-14 18:10:15 +08:00
parent fa6dfc6acb
commit 227f50b9d1
3 changed files with 28 additions and 6 deletions

View File

@@ -4,11 +4,12 @@ require_once __DIR__ . '/vendor/autoload.php';
use Adapterman\Adapterman;
use Workerman\Worker;
Adapterman::init();
$http_worker = new Worker('http://127.0.0.1:7010');
$http_worker->count = getenv('WEBMAN_WORKERS') ?: (swoole_cpu_num() ?: 1);
$http_worker->name = 'AdapterMan';
$http_worker = new Worker('http://127.0.0.1:7010');
$http_worker->count = getenv('WEBMAN_WORKERS') ?: max(swoole_cpu_num(), 2);
$http_worker->name = 'AdapterMan';
$http_worker->onWorkerStart = static function () {
//init();
@@ -17,7 +18,12 @@ $http_worker->onWorkerStart = static function () {
$http_worker->onMessage = static function ($connection, $request) {
static $request_count;
$connection->send(run());
if (++$request_count > 10000) {
Worker::stopAll();
}
};
Worker::runAll();