Laravel

Mini4Work manages the listener and PHP workers. Octane boots Laravel on the first request in each worker and runs the Laravel middleware and route for each request.

Laravel Octane

In an existing Laravel application, install the web server and the Octane version supported by its adapter.

Shell
composer require mini4work/webserver 'laravel/octane:^2.25'

Write a handler

Save this entry point as server.php next to artisan. Pass the Laravel project directory to the Octane adapter.

PHP
<?php

use M4W\WebServer\Adapters\Laravel\OctaneRequestHandler;
use M4W\WebServer\Cli\ServerCommand;

require __DIR__.'/vendor/autoload.php';

exit((new ServerCommand)->run($argv, new OctaneRequestHandler(__DIR__)));

Laravel route

Add this route to routes/web.php. Laravel passes the name from the URL to the callback.

PHP
\Illuminate\Support\Facades\Route::get('/hello/{name}', function (string $name) {
    return response()->json(['message' => "Hello, $name!"]);
});

Start the server

Save this as m4w.json next to server.php.

JSON
{
  "listen": { "port": 9000 }
}
Shell
php server.php m4w.json

In a second terminal, send a request to the loopback listener.

Shell
curl -i http://127.0.0.1:9000/hello/Ada
JSON
{"message": "Hello, Ada!"}

Restart the workers after changing Laravel code. The adapter buffers streamed responses before sending them. Use it for finite downloads.