From 8c85f4da3cfadcd7f71a582105330ded5e06c67d Mon Sep 17 00:00:00 2001 From: Joan Miquel Date: Sat, 9 Nov 2024 19:48:06 +0100 Subject: [PATCH] Optimizations Worker.php Use Null coalescing assignment operator (PHP 7.4) First check if logFile is 'dev/null' and later check if is_file(), so we use one stat less if not necessary. --- src/Worker.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Worker.php b/src/Worker.php index 9ee59544..7c542b6e 100644 --- a/src/Worker.php +++ b/src/Worker.php @@ -713,17 +713,17 @@ protected static function init(): void $startFilePrefix = hash('xxh64', static::$startFile); // Pid file. - static::$pidFile = empty(static::$pidFile) ? sprintf('%s/workerman.%s.pid', dirname(__DIR__), $startFilePrefix) : static::$pidFile; + static::$pidFile ??= sprintf('%s/workerman.%s.pid', dirname(__DIR__), $startFilePrefix); // Status file. - static::$statusFile = empty(static::$statusFile) ? sprintf('%s/workerman.%s.status', dirname(__DIR__), $startFilePrefix) : static::$statusFile; + static::$statusFile ??= sprintf('%s/workerman.%s.status', dirname(__DIR__), $startFilePrefix); static::$statisticsFile ??= static::$statusFile; static::$connectionsFile ??= static::$statusFile . '.connection'; // Log file. - static::$logFile = empty(static::$logFile) ? sprintf('%s/workerman.log', dirname(__DIR__, 2)) : static::$logFile; + static::$logFile ??= sprintf('%s/workerman.log', dirname(__DIR__, 2)); - if (!is_file(static::$logFile) && static::$logFile !== '/dev/null') { + if (static::$logFile !== '/dev/null' && !is_file(static::$logFile)) { // if /runtime/logs default folder not exists if (!is_dir(dirname(static::$logFile))) { @mkdir(dirname(static::$logFile), 0777, true);