diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 599a56814..23e113485 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,6 +2,9 @@ name: tests on: push: + branches: + - master + - '*.x' pull_request: schedule: - cron: '0 0 * * *' @@ -13,9 +16,12 @@ jobs: strategy: fail-fast: true matrix: - php: ['8.0', 8.1] + php: ['8.0', 8.1, 8.2] laravel: [8, 9] driver: [swoole, openswoole] + exclude: + - php: 8.2 + laravel: 8 name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - ${{ matrix.driver }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bb5be279..cdcfa7d07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Release Notes -## [Unreleased](https://github.com/laravel/octane/compare/v1.3.4...1.x) +## [Unreleased](https://github.com/laravel/octane/compare/v1.3.5...1.x) + +## [v1.3.5](https://github.com/laravel/octane/compare/v1.3.4...v1.3.5) - 2022-10-26 + +### Fixed + +- Revert "[1.x] Made Roadrunner log level configurable" by @driesvints in https://github.com/laravel/octane/pull/603 ## [v1.3.4](https://github.com/laravel/octane/compare/v1.3.3...v1.3.4) - 2022-10-24 diff --git a/composer.json b/composer.json index 005084c33..f45d6e6b0 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ ], "require": { "php": "^8.0", - "laravel/framework": "^8.83.25|^9.33", + "laravel/framework": "^8.83.26|^9.38.0", "laminas/laminas-diactoros": "^2.5", "laravel/serializable-closure": "^1.0", "nesbot/carbon": "^2.60", diff --git a/src/Commands/Concerns/InteractsWithServers.php b/src/Commands/Concerns/InteractsWithServers.php index 1392d9c04..f97eb684e 100644 --- a/src/Commands/Concerns/InteractsWithServers.php +++ b/src/Commands/Concerns/InteractsWithServers.php @@ -100,7 +100,7 @@ protected function writeServerRunningMessage() $this->output->writeln([ '', - ' Local: http://'.$this->option('host').':'.$this->option('port').' ', + ' Local: http://'.$this->option('host').':'.$this->getPort().' ', '', ' Press Ctrl+C to stop the server', '', @@ -120,6 +120,16 @@ protected function getServerOutput($server) ], fn () => $server->clearOutput()->clearErrorOutput()); } + /** + * Get the Octane HTTP server port. + * + * @return string + */ + protected function getPort() + { + return $this->option('port') ?? config('octane.port') ?? $_ENV['OCTANE_PORT'] ?? '8000'; + } + /** * Returns the list of signals to subscribe. * diff --git a/src/Commands/StartCommand.php b/src/Commands/StartCommand.php index 7842f10e4..2c1e1e890 100644 --- a/src/Commands/StartCommand.php +++ b/src/Commands/StartCommand.php @@ -16,7 +16,7 @@ class StartCommand extends Command implements SignalableCommandInterface public $signature = 'octane:start {--server= : The server that should be used to serve the application} {--host=127.0.0.1 : The IP address the server should bind to} - {--port=8000 : The port the server should be available on} + {--port= : The port the server should be available on [default: "8000"]} {--rpc-port= : The RPC port the server should be available on} {--workers=auto : The number of workers that should be available to handle requests} {--task-workers=auto : The number of task workers that should be available to handle tasks} @@ -57,7 +57,7 @@ protected function startSwooleServer() { return $this->call('octane:swoole', [ '--host' => $this->option('host'), - '--port' => $this->option('port'), + '--port' => $this->getPort(), '--workers' => $this->option('workers'), '--task-workers' => $this->option('task-workers'), '--max-requests' => $this->option('max-requests'), @@ -75,7 +75,7 @@ protected function startRoadRunnerServer() { return $this->call('octane:roadrunner', [ '--host' => $this->option('host'), - '--port' => $this->option('port'), + '--port' => $this->getPort(), '--rpc-port' => $this->option('rpc-port'), '--workers' => $this->option('workers'), '--max-requests' => $this->option('max-requests'), diff --git a/src/Commands/StartRoadRunnerCommand.php b/src/Commands/StartRoadRunnerCommand.php index fcf3592c7..a201e4b00 100644 --- a/src/Commands/StartRoadRunnerCommand.php +++ b/src/Commands/StartRoadRunnerCommand.php @@ -23,13 +23,14 @@ class StartRoadRunnerCommand extends Command implements SignalableCommandInterfa */ public $signature = 'octane:roadrunner {--host=127.0.0.1 : The IP address the server should bind to} - {--port=8000 : The port the server should be available on} + {--port= : The port the server should be available on} {--rpc-port= : The RPC port the server should be available on} {--workers=auto : The number of workers that should be available to handle requests} {--max-requests=500 : The number of requests to process before reloading the server} {--rr-config= : The path to the RoadRunner .rr.yaml file} {--watch : Automatically reload the server when the application is modified} - {--poll : Use file system polling while watching in order to watch files over a network}'; + {--poll : Use file system polling while watching in order to watch files over a network} + {--log-level= : Log messages at or above the specified log level}'; /** * The command's description. @@ -78,7 +79,7 @@ public function handle(ServerProcessInspector $inspector, ServerStateFile $serve $roadRunnerBinary, '-c', $this->configPath(), '-o', 'version=2.7', - '-o', 'http.address='.$this->option('host').':'.$this->option('port'), + '-o', 'http.address='.$this->option('host').':'.$this->getPort(), '-o', 'server.command='.(new PhpExecutableFinder)->find().' '.base_path(config('octane.roadrunner.command', 'vendor/bin/roadrunner-worker')), '-o', 'http.pool.num_workers='.$this->workerCount(), '-o', 'http.pool.max_jobs='.$this->option('max-requests'), @@ -87,7 +88,7 @@ public function handle(ServerProcessInspector $inspector, ServerStateFile $serve '-o', 'http.static.dir='.base_path('public'), '-o', 'http.middleware='.config('octane.roadrunner.http_middleware', 'static'), '-o', 'logs.mode=production', - '-o', app()->environment('local') ? 'logs.level=debug' : 'logs.level=warn', + '-o', 'logs.level='.($this->option('log-level') ?: (app()->environment('local') ? 'debug' : 'warn')), '-o', 'logs.output=stdout', '-o', 'logs.encoding=json', 'serve', @@ -114,7 +115,7 @@ protected function writeServerStateFile( $serverStateFile->writeState([ 'appName' => config('app.name', 'Laravel'), 'host' => $this->option('host'), - 'port' => $this->option('port'), + 'port' => $this->getPort(), 'rpcPort' => $this->rpcPort(), 'workers' => $this->workerCount(), 'maxRequests' => $this->option('max-requests'), @@ -173,7 +174,7 @@ protected function maxExecutionTime() */ protected function rpcPort() { - return $this->option('rpc-port') ?: $this->option('port') - 1999; + return $this->option('rpc-port') ?: $this->getPort() - 1999; } /** diff --git a/src/Commands/StartSwooleCommand.php b/src/Commands/StartSwooleCommand.php index 4a8ac740b..51da273e9 100644 --- a/src/Commands/StartSwooleCommand.php +++ b/src/Commands/StartSwooleCommand.php @@ -21,7 +21,7 @@ class StartSwooleCommand extends Command implements SignalableCommandInterface */ public $signature = 'octane:swoole {--host=127.0.0.1 : The IP address the server should bind to} - {--port=8000 : The port the server should be available on} + {--port= : The port the server should be available on} {--workers=auto : The number of workers that should be available to handle requests} {--task-workers=auto : The number of task workers that should be available to handle tasks} {--max-requests=500 : The number of requests to process before reloading the server} @@ -105,7 +105,7 @@ protected function writeServerStateFile( $serverStateFile->writeState([ 'appName' => config('app.name', 'Laravel'), 'host' => $this->option('host'), - 'port' => $this->option('port'), + 'port' => $this->getPort(), 'workers' => $this->workerCount($extension), 'taskWorkers' => $this->taskWorkerCount($extension), 'maxRequests' => $this->option('max-requests'), diff --git a/tests/RequestStateTest.php b/tests/RequestStateTest.php index 563528258..72d373bd7 100644 --- a/tests/RequestStateTest.php +++ b/tests/RequestStateTest.php @@ -5,6 +5,7 @@ use Illuminate\Foundation\Application; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Http\Request; +use Illuminate\Routing\Controller; class RequestStateTest extends TestCase { @@ -61,17 +62,22 @@ public function test_request_routes_flush_controller_state() $worker->run(); - $this->assertEquals(1, $client->responses[0]->original); - $this->assertEquals(1, $client->responses[1]->original); + $this->assertEquals(1, $client->responses[0]->original['invokedCount']); + $this->assertEquals(1, $client->responses[0]->original['middlewareInvokedCount']); + $this->assertEquals(1, $client->responses[1]->original['invokedCount']); + $this->assertEquals(1, $client->responses[1]->original['middlewareInvokedCount']); $worker->run(); - $this->assertEquals(1, $client->responses[0]->original); - $this->assertEquals(1, $client->responses[1]->original); + $this->assertEquals(1, $client->responses[0]->original['invokedCount']); + $this->assertEquals(1, $client->responses[0]->original['middlewareInvokedCount']); + $this->assertEquals(1, $client->responses[1]->original['invokedCount']); + $this->assertEquals(1, $client->responses[1]->original['middlewareInvokedCount']); } public function test_request_routes_controller_does_not_leak() { + gc_collect_cycles(); UserControllerStub::$destroyedCount = 0; [$app, $worker, $client] = $this->createOctaneContext([ @@ -93,17 +99,31 @@ public function test_request_routes_controller_does_not_leak() } } -class UserControllerStub +class UserControllerStub extends Controller { + protected $middlewareInvokedCount = 0; + protected $invokedCount = 0; public static $destroyedCount = 0; + public function __construct() + { + $this->middleware(function ($request, $next) { + $this->middlewareInvokedCount++; + + return $next($request); + }); + } + public function __invoke() { $this->invokedCount++; - return $this->invokedCount; + return [ + 'middlewareInvokedCount' => $this->middlewareInvokedCount, + 'invokedCount' => $this->invokedCount, + ]; } public function __destruct()