feat: Add Laravel Octane support by tracking request ID #128
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.
Add Laravel Octane Support by Tracking Request ID
Problem
Laravel Octane keeps the application in memory across multiple requests for improved performance. As documented in the Laravel Octane documentation:
This creates a critical issue for Sushi models: the
bootSushi()method is only called once when the worker process starts, and never gets called again on subsequent requests.Impact
getRows()is never called again after the initial boot, meaning models serve stale dataSolution
This PR implements a request-aware connection resolver that detects when a new request starts and re-boots Sushi, ensuring
getRows()and the migration process run fresh for each request.Changes
$currentRequestIdstatic property to track the current requestgetCurrentRequestId()method that:spl_object_hash()to generate unique IDs for each request instance (Octane-aware)REQUEST_TIME_FLOATresolveConnection(): Now checks if the request has changed and re-boots Sushi when neededHow It Works