Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mutexName inconsistency caused by different PHP binary paths on multiple servers #53811

Merged
merged 6 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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