Laravel Octane does not require any specific built-in settings to be adjusted for Laravel Pennant to work properly. However, there are some important considerations and best practices when using Pennant with Octane due to Octane's persistent memory and request handling model.
Key Points for Using Pennant with Laravel Octane
- Feature Scope and State Management: Pennant features often rely on scopes such as the currently authenticated user or team to determine feature flag status. Since Octane keeps the application in memory between requests, any state related to feature scopes should be resolved fresh for each request to avoid stale or incorrect feature flag evaluations. This is typically done by setting a default scope dynamically in a service provider using `Feature::resolveScopeUsing()`. For example, you might set the scope to the authenticated user's team like this:
php
Feature::resolveScopeUsing(fn ($driver) => Auth::user()?->team);
This ensures that each request evaluates the feature flags against the current user's context, which is crucial under Octane's persistent environment[1].
- Handling Nullable Scopes: Because Octane handles requests in a long-running process, there may be contexts such as Artisan commands, queued jobs, or unauthenticated routes where the scope is `null`. Pennant returns `false` by default for `null` scopes unless the feature definition explicitly supports a nullable scope type. When using Octane, ensure your feature definitions can handle nullable scopes gracefully to avoid unexpected feature flag results[1].
- No Special Octane Configuration Needed for Pennant: Pennant's configuration file (`config/pennant.php`) and its drivers do not require special changes to work with Octane. You just need to ensure that any stateful or scoped logic in your feature flag checks is properly reset or resolved per request, which is a general best practice when using Octane with any stateful service[1][2].
- Custom Drivers and Extensions: If you use a custom Pennant driver, ensure it is compatible with Octaneâs persistent environment. For example, if your driver caches feature states or scopes, it should be designed to refresh or invalidate cache appropriately between requests. This is not specific to Octane but important for any long-running PHP process[1].
Summary
No specific Laravel Octane configuration settings must be changed solely for Pennant to work. The main focus is on ensuring that feature scopes are correctly resolved per request and that nullable scopes are handled properly in feature definitions. This avoids stale state issues due to Octaneâs persistent memory model. Pennant's own configuration and drivers work as usual under Octane without special adjustments.
References:
- Laravel Pennant configuration and scope handling details[1].
- Laravel Octane documentation on request handling and configuration[2].
Citations:
[1] https://laravel.com/docs/11.x/pennant
[2] https://laravel.com/docs/12.x/octane
[3] https://www.youtube.com/watch?v=QgxD94HtlDU
[4] https://github.com/SyedAsadRazaDevops/how-to-incress-speed-Run-Laravel-Octane-using-RoadRunner-with-nginx-configration-
[5] https://laravel.com/docs/11.x/configuration
[6] https://www.youtube.com/watch?v=YGBvdAWt0W8
[7] https://laravel.com/docs/11.x/octane
[8] https://www.youtube.com/watch?v=EjLAaeHSPWY