Skip to content

Commit

Permalink
Optimizations Worker.php
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
joanhey authored Nov 9, 2024
1 parent b103862 commit 8c85f4d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8c85f4d

Please sign in to comment.