During Laracon, Taylor Otwell gave the viewers a first glimpse at Laravel Octane, a new server feature for Laravel that would allow official integration between Laravel and either Swoole or RoadRunner.
Currently, running a Laravel server on something like Nginx or fpm processes requests one at a time, completely restarting the system every time. Even though things are fast (and safe from things like memory leaks), it isn’t the most efficient way to go about handling requests for a webserver. Instead, solutions exist in the PHP world that holds the program in memory and feeds it requests one after another. This increases speed tremendously, allowing requests to be processed at higher and higher rates.
Swoole and RoadRunner are PHP servers that use this method and boast extremely high performance. There are existing packages to use RoadRunner for example, but official support has many advantages. You can rely on the Laravel team to keep up with bugs and expect timely security updates if needed.
In his Laracon segment, Taylor Otwell introduced Octane and demonstrated its capabilities. The rationale for the development of Octane was to offer a “single, unified package for running Laravel at extreme speeds”.
You start octane with the command:
php artisan octane:start --workers=8
with the number of workers optionally specified. This hosts your application on localhost at port 8888, just like using the ‘PHP artisan serve’ command. However, if you make changes to your application, you will have to reload your program into memory with the command:
php artisan octane:reload
Or, you can start your octane server with the optional argument:
php artisan octane:start --watch
Which will automatically reload your application when you make a change.
In terms of performance, Octane was capable of processing over 6 thousand requests per second to a “Hello World” application in the demonstration. This is compared to only around 4 hundred requests from an Nginx server comparison.
Taylor also demonstrated another Laravel Octane: the Octane::route method. Use this route to allow specific endpoints to be extremely fast, much faster than the normal routes. He gave the example that he needed some routes to be much faster than others and that this route was a way to achieve this. This route was able to service requests at over 16 thousand requests per second.
The Octane GitHub page is already live, so be sure to check it out before Octane is officially released.
If you would like to learn more, take a look at the following sources.