Expired view cache check causing issues with my deployment script #53394
Replies: 7 comments 1 reply
-
Hey there! 👋 This is an interesting observation, and it comes up sometimes in automated deployment workflows. The reason Laravel uses >= instead of > for checking if a view is expired is to avoid unnecessary recompilation in typical workflows. However, in cases like yours where a deployment script can lead to identical timestamps, this behavior can cause unexpected results.
I hope one of these solutions works for you! Let me know if you need any more help with this. 😊 |
Beta Was this translation helpful? Give feedback.
-
Your response sounds oddly like ChatGPT... My deployment script shouldn't be atypical. The Laravel documentation says: "When deploying your application to production, you should make sure that you run the Your I ended up adding a small delay using |
Beta Was this translation helpful? Give feedback.
-
Hi everyone, I have a suggestion for adding a new configuration option called USE_STRICT_VIEW_CACHE_COMPARISON to solve this issue. Implementing this feature wouldn't be difficult for me and would probably take about an hour. I believe it could completely resolve the problem you're facing. Initially, I considered simply changing >= to >, but that approach had its own set of complications. If you have any other ideas or thoughts, I'd be more than happy to hear them and collaborate further! I haven't participated in open source projects before, and I think this could be a great starting point for me. |
Beta Was this translation helpful? Give feedback.
-
Hi @adel007gh, I'd be interested to hear the set of complications that come from changing The only issue with |
Beta Was this translation helpful? Give feedback.
-
Thanks @jlswanson28694 Concurrency Issues: As you pointed out, if two processes are running concurrently (e.g., one executing view:cache while another pulls changes from Git), there is a possibility, however minimal, that the compiled view could be out of sync. This could potentially serve outdated views if one step completes just before the other updates the source. Clock Precision: Another subtle issue involves the precision of timestamps. If the system’s clock or the file system’s granularity for timestamps is not accurate to the second or is slightly off, it could lead to unexpected results where > might not trigger a recompilation when it should. Compatibility and User Expectations: Changing to > might break the expectations for users relying on the current behavior (>=). For example, automated deployments that don’t always use view:cache might unintentionally serve outdated views without explicit recompilation steps. Custom Use Cases: Some users might have custom workflows or scripts that expect >= behavior, where any modification time matching the compiled view time still considers it valid. I believe adding an option like USE_STRICT_VIEW_CACHE_COMPARISON could indeed offer flexibility, allowing developers to choose the behavior that suits their deployment needs. I’d love to hear if you or others have any additional thoughts or scenarios that could help refine this idea. |
Beta Was this translation helpful? Give feedback.
-
This is another ChatGPT answer, and I'm still not convinced Adding a new config option to toggle this behavior seems like overkill in my opinion. I'd change |
Beta Was this translation helpful? Give feedback.
-
You should just do |
Beta Was this translation helpful? Give feedback.
-
Laravel Version
10.48.22
PHP Version
8.1.2
Database Driver & Version
No response
Description
I use a simple deployment bash script that runs
git pull
followed by some cache commands, includingphp artisan view:cache
. This can often result in the last modified timestamp of a Blade file having the same timestamp as its corresponding compiled view. Laravel's view compiler uses a>=
comparison when checking if the compiled view is expired, which means all the views compiled in my deployment script aren't being used. Is there a reason why it can't use a>
comparison instead?https://github.com/laravel/framework/blob/11.x/src/Illuminate/View/Compilers/Compiler.php#L112
Steps To Reproduce
php artisan view:cache
.Illuminate\Filesystem\Filesystem::lastModified
to check the timestamp of the modified Blade file and compare it to the timestamp of any compiled view. You will see they are the same.Beta Was this translation helpful? Give feedback.
All reactions