Laravel Octane: Boost Your Project’s Performance

Laravel Octane Logo

When it comes to performance in Laravel, one of the biggest advancements from the community in recent years has been Laravel Octane. It was designed to optimize application execution by keeping the framework in memory between requests, eliminating the need to “boot” Laravel on every HTTP request.

What Is Laravel Octane?

Laravel Octane is an official package that integrates Laravel with high-performance application servers such as Swoole and RoadRunner. These servers allow your PHP application to run persistently, keeping the environment loaded and ready to process new requests without the overhead of traditional initialization.

Key Benefits

  • Up to 10x better performance: Thanks to continuous execution, response times can be significantly reduced.
  • Greater scalability: Ideal for high-traffic applications.
  • Efficient resource usage: Reduces CPU and memory overhead per request.
  • Support for asynchronous tasks: Especially with Swoole, it is possible to handle multiple simultaneous connections.

Getting Started

Installation is simple:

$ composer require
$ laravel/octane php artisan
$ octane:install php artisan
$ octane:start --server=swoole

Done! Your application will now be running with the Swoole server, and you should already notice performance improvements.

Optimization Tips

  1. Avoid mutable global variables, as the server persists between requests.

  2. Use caching wisely, taking advantage of the workers’ lifecycle.

  3. Monitor memory usage, as persistent processes require careful memory management.

When to Use It

Laravel Octane is ideal for APIs, real-time applications, and systems that need to handle a large number of requests per second. For smaller projects or shared hosting environments, the performance gains may not justify the additional complexity.

If performance is a critical factor for your Laravel project, Octane is a powerful tool that can completely transform the user experience and reduce your system’s operational costs.

Performance Testing

Local test with AB (Apache Benchmark)

Apache Benchmark is a simple and lightweight tool for measuring requests per second and average response time.

Installation (Linux/Mac):

$ sudo apt install apache2-utils       

Test command:

$ ab -n 1000 -c 50 http://127.0.0.1:8000/
  • -n 1000 — total number of requests;

  • -c 50 — number of concurrent connections.

Compare the results with:

  • Standard Laravel (php artisan serve);

  • Laravel Octane (php artisan octane:start --server=swoole).

Look at the Requests per second field. You should notice a significant increase when using Octane.

Test with WRK

wrk is even more powerful and supports high-intensity concurrent connections.

Installation:

sudo apt install wrk

Test example:

$ wrk -t4 -c100 -d30s http://127.0.0.1:8000/
  • -t4 — 4 threads;

  • -c100 — 100 connections;

  • -d30s — test duration (30 seconds).

As a result, you will get the average latency, requests per second, and total data transferred.

Scroll to Top