The af-octane:test command is a comprehensive Laravel Octane compatibility scanner that detects code patterns that may cause issues when running your application with Laravel Octane. It scans your entire codebase for singleton misuse, static state, memory leaks, and other Octane-incompatible patterns.
php artisan af-octane:test [options]
| Option | Description |
|---|---|
--json |
Output results in JSON format (useful for CI/CD pipelines) |
--ci |
CI mode - exits with error code if critical issues are found |
--fix |
Apply automatic fixes where possible (not yet implemented) |
--path= |
Specific path to scan (default: app/) |
The analyzer includes 11 specialized scanners that check for:
app()->singleton(), App::singleton(), and bind(..., shared: true) callsrequest(), Auth::user(), session() in singletonsAuth::user(), auth()->user() in constructorsrequest(), Request:: in constructorssession(), Session:: in constructorsCookie:: facade in boot methodsconfig([...]) setting config arraysConfig::set()putenv()$_ENV[] or $_SERVER[] assignmentsDB::connection() without disconnect()barryvdh/laravel-debugbar (high risk - static state)barryvdh/laravel-ide-helper (low risk - dev only)spatie/laravel-ignition (medium risk - debug mode)rap2hpoutre/laravel-log-viewer (medium risk - memory issues)render() without paginationemit() instead of dispatch()[@php](https://github.com/php) blocks$GLOBALS[]handle() methodShouldQueueShouldBeUnique interfacewhile(true))Cache::rememberForever() without invalidation╔══════════════════════════════════════════════════════════════╗
║ 🚀 Laravel Octane Safety Analyzer 🚀 ║
╚══════════════════════════════════════════════════════════════╝
📊 SCAN SUMMARY
⏱️ Execution Time: 0.99s
📁 Files Scanned: 312
✅ Passed Checks: 2
⚠️ Warnings: 3
❌ Critical Issues: 0
🔍 Singleton Binding Scanner
────────────────────────────────────────────────────────────
⚠️ [MEDIUM] Singleton Binding Detected
📄 File: app/Providers/AppServiceProvider.php
📍 Line: 42
💬 Singleton binding found. Verify this service doesn't store request-specific state
💡 Fix: Review the singleton implementation. If it stores per-request data, convert to scoped binding
--json){
"summary": {
"execution_time": 0.99,
"files_scanned": 312,
"passed_checks": 2,
"warnings": 3,
"critical_issues": 0
},
"results": {
"singleton": {
"name": "Singleton Binding Scanner",
"description": "Detects singleton bindings that may cause issues with Laravel Octane",
"scan_time": 0.0034,
"vulnerabilities": [
{
"title": "Singleton Binding Detected",
"severity": "medium",
"description": "Singleton binding found...",
"file": "app/Providers/AppServiceProvider.php",
"line": 42,
"code": "$this->app->singleton(MyService::class);",
"recommendation": "Review the singleton implementation...",
"metadata": {
"binding_type": "->singleton()"
}
}
]
}
}
}
| Level | Icon | Description |
|---|---|---|
| CRITICAL | ❌ | Must fix before Octane deployment |
| HIGH | 🔴 | Should fix - likely to cause issues |
| MEDIUM | ⚠️ | Review and fix if applicable |
| LOW | ⚡ | Best practice suggestions |
0: Success (no critical issues)1: Failure (critical issues found in --ci mode)name: Octane Safety Check
on: [push, pull_request]
jobs:
octane-scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
- name: Install Dependencies
run: composer install
- name: Run Octane Safety Analyzer
run: php artisan af-octane:test --ci --json > octane-report.json
- name: Upload Report
uses: actions/upload-artifact@v2
if: always()
with:
name: octane-safety-report
path: octane-report.json
php artisan af-octane:test
php artisan af-octane:test --path=app/Services
php artisan af-octane:test --json > octane-report.json
php artisan af-octane:test --ci
Problem:
// AppServiceProvider.php
$this->app->singleton(UserService::class, function ($app) {
return new UserService(auth()->user()); // ❌ Wrong!
});
Fix:
// AppServiceProvider.php
$this->app->scoped(UserService::class, function ($app) {
return new UserService(auth()->user()); // ✅ Correct!
});
Problem:
class ReportGenerator
{
private static $currentUser; // ❌ Wrong!
public function generate()
{
self::$currentUser = auth()->user();
}
}
Fix:
class ReportGenerator
{
private $currentUser; // ✅ Correct!
public function generate()
{
$this->currentUser = auth()->user();
}
}
Problem:
class MyService
{
private $user;
public function __construct()
{
$this->user = Auth::user(); // ❌ Wrong!
}
}
Fix:
class MyService
{
public function doSomething()
{
$user = Auth::user(); // ✅ Correct!
// Use $user here
}
}
Problem:
Cache::rememberForever('users', function () {
return User::all(); // ❌ Wrong - shared across tenants!
});
Fix:
Cache::rememberForever('tenant:' . tenant('id') . ':users', function () {
return User::all(); // ✅ Correct - tenant-specific!
});
After running the analyzer, consider these best practices:
php artisan octane:start and test your appphp artisan octane:status to check worker healthscoped() over singleton() for request-specific dataOctane::tick('clear-state', function () {
MyService::clearCache();
});
--fix is used)--fix flag not yet implemented (planned for future release)--fix flag for automatic refactoringFor issues or questions:
This analyzer is part of the artflow-studio/laravel-security package.
How can I help you explore Laravel packages today?