Use swoole_cpu_num instead of shelling out before the server starts

This commit is contained in:
Jonathan Sykes
2026-10-14 03:16:14 +08:00
parent d5a175cf45
commit 83f4a121d1

View File

@@ -154,7 +154,7 @@ $streamsPayload = static function(string $id,array $row): array {
}; };
$server = new Server('0.0.0.0',$port,SWOOLE_PROCESS,SWOOLE_SOCK_TCP); $server = new Server('0.0.0.0',$port,SWOOLE_PROCESS,SWOOLE_SOCK_TCP);
$cpu=max(1,(int)(shell_exec('getconf _NPROCESSORS_ONLN 2>/dev/null') ?: 1)); $cpu=max(1,(int)(function_exists('swoole_cpu_num') ? swoole_cpu_num() : 1));
$server->set(['worker_num'=>$cpu,'max_request'=>10000,'dispatch_mode'=>2,'enable_coroutine'=>true,'http_compression'=>false,'package_max_length'=>8*1024*1024,'open_tcp_nodelay'=>true,'log_level'=>SWOOLE_LOG_WARNING]); $server->set(['worker_num'=>$cpu,'max_request'=>10000,'dispatch_mode'=>2,'enable_coroutine'=>true,'http_compression'=>false,'package_max_length'=>8*1024*1024,'open_tcp_nodelay'=>true,'log_level'=>SWOOLE_LOG_WARNING]);
$server->on('WorkerStart', function() use (&$store,&$media,$dbPath,$mediaDir,$mediaMarker,$mediaBudget,$ytDlpPath,$ffmpegPath,$ffprobePath) { $server->on('WorkerStart', function() use (&$store,&$media,$dbPath,$mediaDir,$mediaMarker,$mediaBudget,$ytDlpPath,$ffmpegPath,$ffprobePath) {
$store = new Store($dbPath, false); $store = new Store($dbPath, false);