Repository navigation
[13.x] Make health route compatible with route caching across machines - #62049
Merged
taylorotwell merged 1 commit intoOct 16, 2026
Merged
taylorotwell merged 1 commit into
taylorotwell merged 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The problem
The
healthroute registered bywithRouting(health: '/up')is a closure that renders its view by absolute path:When routes are cached,
route:cacheserializes route closures withlaravel/serializable-closure. Serializing a closure turns magic constants into literal strings, so__DIR__is stored as the absolute path of the machine that ranroute:cache. The cached route then looks like this:Many deployments cache routes during a build step and run the application from a different path:
.vapor/build/app(for example on a CI runner) and runs from/var/taskphp artisan optimizein one stage and copy the app to another pathIn all of these, every request to
/upfails with:The view file exists in the deployed application. It is only looked up at the build machine's path. Applications can't work around this without dropping
health:or giving up route caching, because the closure lives inside the framework.The fix
This PR moves the closure body, unchanged, into an invokable class,
Illuminate\Foundation\Http\HealthCheck, and registers the route as:A controller route is cached as the string
Illuminate\Foundation\Http\HealthCheck@__invokeinstead of a serialized closure.__DIR__inside the class is then evaluated at request time, on the machine actually serving the request, so the view always resolves. This follows the same approach asIlluminate\Filesystem\ServeFile, which the framework already uses for local storage serving.Behaviour is otherwise identical:
DiagnosingHealthis still dispatched, exceptions are still rethrown in debug mode and otherwise reported with a 500, and the JSON{"status": "up"|"down"}response is still returned when the request expects JSON.I also considered registering the view under a view namespace (like
laravel-exceptions) and rendering it by name. That makesview:cachecompile everything in that directory, including the exception renderer views, and it brokeOptimizeCommandTest. The invokable class avoids that and keeps the change self-contained.Tests
test_health_route_can_be_cached_without_absolute_pathsprepares the/uproute for serialization, the same wayroute:cachedoes, and asserts that the cached action doesn't contain the framework's absolutesrcpath. Without this change the test fails, and its output shows the absolute__DIR__path inlined in the serialized closure. With the change it passes.🤖 Generated with Claude Code