{"id":391,"date":"2025-08-27T20:55:37","date_gmt":"2025-08-27T20:55:37","guid":{"rendered":"https:\/\/1v0.net\/blog\/?p=391"},"modified":"2025-08-27T20:55:39","modified_gmt":"2025-08-27T20:55:39","slug":"optimizing-laravel-for-high-concurrency-with-octane","status":"publish","type":"post","link":"https:\/\/1v0.net\/blog\/optimizing-laravel-for-high-concurrency-with-octane\/","title":{"rendered":"Optimizing Laravel for High Concurrency with Octane"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><strong>Optimizing Laravel for High Concurrency with Octane<\/strong><\/h2>\n\n\n\n<p>By default, Laravel boots the entire framework on every request. This design is flexible but adds overhead. <strong>Laravel Octane<\/strong> removes that overhead by keeping the app in memory between requests using <strong>Swoole<\/strong> or <strong>RoadRunner<\/strong>. The result? Apps that handle thousands of requests per second with minimal latency. In this guide, we\u2019ll install Octane, configure workers, run benchmarks, and compare results.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\"><strong>1 &#8211; Install Octane<\/strong><\/h2>\n\n\n\n<p>Install Octane and choose a server engine. Swoole is the most feature-rich option.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">composer require laravel\/octane\nphp artisan octane:install\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This installs Octane\u2019s service provider and config. You\u2019ll be asked to choose Swoole or RoadRunner. Swoole provides task workers, coroutines, and better concurrency support.<\/p>\n\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\"><strong>2 &#8211; Running Octane<\/strong><\/h2>\n\n\n\n<p>You can run Octane with Artisan. By default, it uses port 8000.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">php artisan octane:start --server=swoole --port=8000\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This boots Laravel once, then keeps it in memory across requests. Startup overhead (autoloading, config, service providers) is eliminated on subsequent requests.<\/p>\n\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\"><strong>3 &#8211; Worker Configuration<\/strong><\/h2>\n\n\n\n<p>Octane uses workers to handle requests. Configure workers in <code>config\/octane.php<\/code>.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\">\/\/ config\/octane.php (snippet)<\/span>\n<span class=\"hljs-string\">'workers'<\/span> =&gt; <span class=\"hljs-number\">8<\/span>,\n<span class=\"hljs-string\">'task_workers'<\/span> =&gt; <span class=\"hljs-number\">4<\/span>,\n<span class=\"hljs-string\">'max_requests'<\/span> =&gt; <span class=\"hljs-number\">1000<\/span>,\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><code>workers<\/code> are processes handling HTTP requests. <code>task_workers<\/code> run async tasks like broadcasting or sending emails. <code>max_requests<\/code> controls how many requests a worker handles before restarting (to free memory leaks).<\/p>\n\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\"><strong>4 &#8211; Benchmarking Octane<\/strong><\/h2>\n\n\n\n<p>Let\u2019s compare performance using <code>ab<\/code> (Apache Bench) or <code>wrk<\/code>. First, test the default PHP-FPM setup:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\"><span class=\"hljs-comment\"># Default PHP-FPM (without Octane)<\/span>\nab -n 1000 -c 50 http:\/\/127.0.0.1:8000\/\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Typical result: ~200 requests\/sec with ~50ms latency.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\"><span class=\"hljs-comment\"># With Octane + Swoole<\/span>\nab -n 1000 -c 50 http:\/\/127.0.0.1:8000\/\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Typical result: ~1,500 requests\/sec with ~5ms latency. That\u2019s a <strong>7x performance boost<\/strong> just by running under Octane.<\/p>\n\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\"><strong>5 &#8211; Octane Tasks<\/strong><\/h2>\n\n\n\n<p>Swoole\u2019s task workers let you run async jobs without queues. This is useful for lightweight background tasks.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\">\/\/ routes\/web.php<\/span>\n<span class=\"hljs-keyword\">use<\/span> <span class=\"hljs-title\">Laravel<\/span>\\<span class=\"hljs-title\">Octane<\/span>\\<span class=\"hljs-title\">Facades<\/span>\\<span class=\"hljs-title\">Octane<\/span>;\n\nRoute::get(<span class=\"hljs-string\">'\/report'<\/span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-params\">()<\/span> <\/span>{\n    Octane::concurrently(&#91;\n        fn () =&gt; DB::table(<span class=\"hljs-string\">'users'<\/span>)-&gt;count(),\n        fn () =&gt; DB::table(<span class=\"hljs-string\">'orders'<\/span>)-&gt;count(),\n    ]);\n});\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This runs multiple DB queries concurrently inside Octane. Great for speeding up dashboards and reports. For larger workloads (like sending thousands of emails), stick to <a href=\"\/blog\/how-to-use-laravel-queues-for-faster-performance\">queues<\/a>.<\/p>\n\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\"><strong>6 &#8211; Combining Octane with Caching<\/strong><\/h2>\n\n\n\n<p>Octane boosts raw performance, but combining it with <a href=\"\/blog\/caching-strategies-in-laravel-redis-vs-database-vs-file\">Redis caching<\/a> makes apps both fast and efficient. Cached queries served from memory under Swoole can drop response times to under 2ms.<\/p>\n\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\"><strong>7 &#8211; Monitoring Octane Performance<\/strong><\/h2>\n\n\n\n<p>Octane removes Laravel\u2019s per-request boot, which means memory leaks or long-running tasks can degrade performance. Monitor with <a href=\"\/blog\/using-laravel-telescope-to-debug-performance-issues\">Telescope<\/a> or external tools like New Relic and Blackfire.<\/p>\n\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>Laravel Octane is a game-changer for high concurrency. By keeping the app in memory, Octane delivers massive performance boosts with minimal changes to your code. We installed Octane, configured workers, benchmarked performance, ran concurrent tasks, and combined it with caching. With proper monitoring and queues, Octane lets Laravel handle enterprise-scale traffic with ease.<\/p>\n\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\">What\u2019s Next<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"\/blog\/10-proven-ways-to-optimize-laravel-for-high-traffic\">10 Proven Ways to Optimize Laravel for High Traffic<\/a> \u2014 Octane is just one piece of the optimization puzzle.<\/li>\n<li><a href=\"\/blog\/caching-strategies-in-laravel-redis-vs-database-vs-file\">Caching Strategies in Laravel: Redis vs Database vs File<\/a> \u2014 combine Octane with effective caching strategies.<\/li>\n<li><a href=\"\/blog\/using-laravel-telescope-to-debug-performance-issues\">Using Laravel Telescope to Debug Performance Issues<\/a> \u2014 monitor queries, requests, and memory leaks in Octane apps.<\/li>\n<\/ul>\n\n","protected":false},"excerpt":{"rendered":"<p>Optimizing Laravel for High Concurrency with Octane By default, Laravel boots the entire framework on every request. This design is flexible but adds overhead. Laravel Octane removes that overhead by keeping the app in memory between requests using Swoole or RoadRunner. The result? Apps that handle thousands of requests per second with minimal latency. In [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":395,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[68,44,64],"class_list":["post-391","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","tag-octane","tag-performance","tag-scaling"],"_links":{"self":[{"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/posts\/391","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/comments?post=391"}],"version-history":[{"count":1,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/posts\/391\/revisions"}],"predecessor-version":[{"id":394,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/posts\/391\/revisions\/394"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/media\/395"}],"wp:attachment":[{"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/media?parent=391"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/categories?post=391"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/tags?post=391"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}