Fix mutexName inconsistency caused by different PHP binary paths on multiple servers #53811
+21
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem Description:
Our production environment handles around 200 million requests daily, and we initially had three Ubuntu 22.04 servers running PHP 8.3, where the PHP executable path was:
Recently, we decided to expand the infrastructure and added a fourth server running AlmaLinux 9.5. While the setup was consistent across servers, the PHP executable path on the new server differed:
This caused an issue with the
mutexName
function when using Laravel’sonOneServer()->withoutOverlapping()
feature for scheduling commands. The$this->command
string varied between servers as follows:Root Cause:
The
mutexName
function generates a unique name based on the$this->command
. Since the PHP executable paths differed across servers, the resulting mutex name was inconsistent. This led to the same scheduled command being executed on multiple servers simultaneously, despite using->onOneServer()->withoutOverlapping()
.Real-Life Impact:
For example, when scheduling the following command in
Kernel.php
:The inconsistency in
mutexName
caused the command to run:This behavior defeats the purpose of
->withoutOverlapping()
, which was critical in our case (high-traffic production environment).Solution:
To resolve this issue, I updated the code to strip the PHP binary path from the
$this->command
. By doing this, themutexName
function will now generate consistent names regardless of the PHP executable's location or version.For example:
or
The mutex name will now be derived only from the relevant parts of the command (i.e.,
'artisan' my-command-signature-here
), ensuring consistency across servers.Testing Considerations:
Unfortunately, testing this specific scenario programmatically is challenging because it requires:
Given these constraints, I was unable to include automated tests for this PR. However, the issue has been thoroughly tested in our production environment, and the proposed change resolves the problem reliably.