Sales2 min read290 words

What is Laravel Octane?

Recai Atak

PlusClouds Author

Cloud & SaaS

What is Laravel Octane?

Laravel Octane allows you to serve your Laravel application using a powerful Swoole and/or Roadrunner Application Server for PHP. Laravel Octane starts your application in a powerful and optimized manner, retains it in memory for specific areas, cleans up object states, and manages object instances between requests.

 Laravel Octane Original Documentation

  https://github.com/laravel/octane

Normally, the application and all objects are loaded multiple times for each request. With Laravel Octane, the application and object models are shared between requests. This means that the developer only needs to load certain objects once (note that some are loaded once at boot time), and in this case, Laravel Octane helps manage the states of the objects.

What is RoadRunner? 

RoadRunner is a load balancer process manager written for PHP applications.


Steps to Create the Application:


We are installing the Laravel installer

composer global require laravel/installer


We are creating a new Laravel project

laravel new laravel-octane


We enter the directory where our project is located

cd laravel-octane


We are installing our package via Composer

composer require laravel/octane


We are loading our package

php artisan octane:install


We are starting our application
php artisan octane:start --port=8002

Yes, our application is now running on Octane. Octane begins to listen to and cache the general PHP core. It should be noted here that since Octane does not know about your dynamic changes, you can only notify these using the Cache Facade.

Cache::driver('octane')->put('test','test')

We have currently started our application on port 8002. However, what we should know here is that you must log in through the port where Laravel is running directly, not through php-fpm. Otherwise, Octane will not work.


Benchmark



Standard Nginx


Laravel Octane



As can be seen, there is a difference of up to 4 times in between.


#There is no text provided for translation. Please provide the text you would like to be translated into English.

Frequently Asked Questions

What is Laravel Octane and what does it do?

Laravel Octane lets you serve your Laravel app on Swoole or RoadRunner. It starts the application in memory, keeps it available between requests, and manages object states and instances to improve performance.

What is RoadRunner in the context of Laravel Octane?

RoadRunner is a load balancer process manager written for PHP applications. Laravel Octane can use RoadRunner as the application server.

How do I install and set up Laravel Octane?

To set up Octane, start by installing the Laravel installer with composer global require laravel/installer, then create a new Laravel project named laravel-octane. Next, enter the project directory, install the Octane package with composer require laravel/octane, and run php artisan octane:install to load it. Finally, start the application with php artisan octane:start --port=8002.

How does Laravel Octane manage memory and object state between requests?

In normal PHP request handling, the application and all objects are loaded for each request. With Octane, the app and object models are shared between requests, so some objects are loaded once at boot and reused, while Octane manages their states. If you need to reflect dynamic changes, use the Cache facade.

What is the difference between standard request handling and Laravel Octane's approach?

Normally, the application and all objects are loaded multiple times for each request. With Octane, the app and object models are shared between requests, reducing repeated loading and helping maintain state.

Do I need to access Octane on the same port Laravel is running, and not through php-fpm?

Yes, you must log in through the port where Laravel is running directly, not via php-fpm. Otherwise, Octane will not work.

What performance improvements can I expect with Laravel Octane?

The benchmark section compares standard Nginx to Laravel Octane and shows up to a fourfold difference. This indicates potential performance gains in suitable setups.

Can Laravel Octane use Swoole or RoadRunner as its application server?

Yes, Laravel Octane can serve your application using Swoole and/or RoadRunner. You can use either as the application server, or both.