Skip to content

Commit

Permalink
Fix mutexName inconsistency caused by different PHP binary paths on m…
Browse files Browse the repository at this point in the history
…ultiple servers (laravel#53811)

* [11.x] Fix mutexName inconsistency caused by different PHP binary paths on multiple servers

* Update Event.php

* Add Event::getNormalizedCommand method to normalize PHP binary path in commands

* Revert EventTest changes

* Remove additional tab

* formatting

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
waska14 and taylorotwell authored Dec 16, 2024
1 parent 06fe535 commit 3903c5d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
21 changes: 20 additions & 1 deletion src/Illuminate/Console/Scheduling/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use GuzzleHttp\Client as HttpClient;
use GuzzleHttp\ClientInterface as HttpClientInterface;
use GuzzleHttp\Exception\TransferException;
use Illuminate\Console\Application;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Contracts\Mail\Mailer;
Expand Down Expand Up @@ -811,7 +812,8 @@ public function mutexName()
return $mutexNameResolver($this);
}

return 'framework'.DIRECTORY_SEPARATOR.'schedule-'.sha1($this->expression.$this->command);
return 'framework'.DIRECTORY_SEPARATOR.'schedule-'.
sha1($this->expression.$this->normalizeCommand($this->command ?? ''));
}

/**
Expand All @@ -838,4 +840,21 @@ protected function removeMutex()
$this->mutex->forget($this);
}
}

/**
* Format the given command string with a normalized PHP binary path.
*
* @param string $command
* @return string
*/
public static function normalizeCommand($command)
{
return str_replace([
Application::phpBinary(),
Application::artisanBinary(),
], [
'php',
preg_replace("#['\"]#", '', Application::artisanBinary()),
], $command);
}
}
6 changes: 1 addition & 5 deletions src/Illuminate/Console/Scheduling/ScheduleListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Closure;
use Cron\CronExpression;
use DateTimeZone;
use Illuminate\Console\Application;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
Expand Down Expand Up @@ -123,10 +122,7 @@ private function listEvent($event, $terminalWidth, $expressionSpacing, $repeatEx
$description = $event->description ?? '';

if (! $this->output->isVerbose()) {
$command = str_replace([Application::phpBinary(), Application::artisanBinary()], [
'php',
preg_replace("#['\"]#", '', Application::artisanBinary()),
], $command);
$command = $event->normalizeCommand($command);
}

if ($event instanceof CallbackEvent) {
Expand Down

0 comments on commit 3903c5d

Please sign in to comment.