Top Related Projects
High performance HTTP server based on Swoole. Speed up your Laravel or Lumen applications.
A non-blocking concurrency framework for PHP applications. 🐘
Event-driven, non-blocking I/O with PHP.
Quick Overview
Laravel Octane is a high-performance application server for Laravel applications. It supercharges Laravel's performance by serving applications using Swoole or RoadRunner, allowing for long-running processes and reduced PHP bootstrapping overhead.
Pros
- Significantly improved application performance and reduced response times
- Ability to handle more concurrent requests with fewer server resources
- Seamless integration with existing Laravel applications
- Support for both Swoole and RoadRunner servers
Cons
- Requires additional server configuration and setup
- Not all Laravel features and third-party packages are fully compatible
- Potential memory leaks if application state is not managed properly
- Learning curve for developers unfamiliar with long-running PHP processes
Code Examples
- Starting an Octane server:
php artisan octane:start
- Defining a task to run on each worker:
use Laravel\Octane\Events\WorkerStarting;
$this->app['events']->listen(WorkerStarting::class, function () {
Cache::flush();
});
- Using Octane's concurrent method for parallel processing:
use Laravel\Octane\Facades\Octane;
[$users, $orders] = Octane::concurrently([
fn () => User::all(),
fn () => Order::all(),
]);
Getting Started
- Install Laravel Octane via Composer:
composer require laravel/octane
- Install a compatible application server (Swoole or RoadRunner):
pecl install swoole
or
composer require spiral/roadrunner
- Publish the Octane configuration file:
php artisan octane:install
- Start the Octane server:
php artisan octane:start
Your Laravel application is now running with Octane! For more advanced configuration and usage, refer to the official Laravel Octane documentation.
Competitor Comparisons
High performance HTTP server based on Swoole. Speed up your Laravel or Lumen applications.
Pros of Laravel-Swoole
- Longer history and more mature project, potentially offering better stability
- More focused on Swoole integration, which may provide deeper Swoole-specific optimizations
- Lighter weight and potentially easier to integrate for projects already using Swoole
Cons of Laravel-Swoole
- Less actively maintained compared to Octane
- Limited to Swoole runtime, while Octane supports multiple runtimes (Swoole and RoadRunner)
- May lack some of the advanced features and optimizations present in Octane
Code Comparison
Laravel-Swoole configuration:
'swoole' => [
'http' => [
'host' => env('SWOOLE_HTTP_HOST', '127.0.0.1'),
'port' => env('SWOOLE_HTTP_PORT', 1215),
'options' => [
'worker_num' => env('SWOOLE_HTTP_WORKER_NUM', 4),
],
],
],
Octane configuration:
'swoole' => [
'server' => env('OCTANE_SERVER', '127.0.0.1'),
'port' => env('OCTANE_PORT', 8000),
'workers' => env('OCTANE_WORKERS', 4),
'task_workers' => env('OCTANE_TASK_WORKERS', 0),
],
Both projects aim to enhance Laravel performance using Swoole, but Octane offers a more comprehensive solution with additional features and runtime options. Laravel-Swoole may be preferable for projects specifically focused on Swoole integration, while Octane provides a more versatile and actively developed solution for high-performance Laravel applications.
A non-blocking concurrency framework for PHP applications. 🐘
Pros of Amp
- Lightweight and flexible, allowing for more granular control over asynchronous operations
- Supports a wider range of PHP versions, including older ones
- Can be used in various contexts beyond web applications, such as CLI scripts and microservices
Cons of Amp
- Steeper learning curve compared to Octane's integration with Laravel
- Smaller ecosystem and community support
- Requires more manual configuration and setup for web applications
Code Comparison
Amp:
Loop::run(function () {
$response = yield $client->request('GET', 'https://example.com');
$body = yield $response->getBody()->buffer();
echo $body;
});
Octane:
Route::get('/', function () {
$response = Http::get('https://example.com');
return $response->body();
});
The Amp example demonstrates its event loop and coroutine-based approach, while Octane leverages Laravel's familiar routing and HTTP client. Octane's code is more concise and integrates seamlessly with Laravel's ecosystem, whereas Amp provides more fine-grained control over asynchronous operations but requires more setup and understanding of its concepts.
Event-driven, non-blocking I/O with PHP.
Pros of ReactPHP
- More lightweight and flexible, allowing for custom implementations
- Supports a wider range of PHP versions (5.3+)
- Can be used for various types of applications beyond web servers
Cons of ReactPHP
- Steeper learning curve, especially for developers new to asynchronous programming
- Requires more manual configuration and setup compared to Octane
- Less integrated with existing PHP frameworks
Code Comparison
ReactPHP:
$loop = React\EventLoop\Factory::create();
$socket = new React\Socket\Server('127.0.0.1:8080', $loop);
$http = new React\Http\Server($socket);
$http->on('request', function (Psr\Http\Message\ServerRequestInterface $request) {
return new React\Http\Response(200, ['Content-Type' => 'text/plain'], "Hello World!\n");
});
$loop->run();
Octane (with Laravel):
use Laravel\Octane\Facades\Octane;
Octane::route('GET', '/', function () {
return response('Hello World!');
});
Octane::start();
ReactPHP offers more granular control over the server setup, while Octane provides a more streamlined approach integrated with Laravel's ecosystem. ReactPHP's flexibility comes at the cost of more verbose code, whereas Octane's simplicity may limit customization options for advanced use cases.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Introduction
Laravel Octane supercharges your application's performance by serving your application using high-powered application servers, including FrankenPHP, Open Swoole, Swoole, and RoadRunner. Octane boots your application once, keeps it in memory, and then feeds it requests at supersonic speeds.
Official Documentation
Documentation for Octane can be found on the Laravel website.
Contributing
Thank you for considering contributing to Octane! You can read the contribution guide here.
Code of Conduct
In order to ensure that the Laravel community is welcoming to all, please review and abide by the Code of Conduct.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
License
Laravel Octane is open-sourced software licensed under the MIT license.
Top Related Projects
High performance HTTP server based on Swoole. Speed up your Laravel or Lumen applications.
A non-blocking concurrency framework for PHP applications. 🐘
Event-driven, non-blocking I/O with PHP.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot