Laravel Performance Optimization: 27 Wins We Ship in Production
The exact performance checklist we run on every Laravel app — Octane, caching, queues, N+1, opcache, database, and frontend. Numbers included.
TL;DR
Most Laravel apps waste 60–90% of their potential performance. The wins are boring: caching, eager loading, opcache, Redis, Octane.
Level 1 — Framework config (30 minutes)
php artisan optimizein production.APP_DEBUG=falseandLOG_LEVEL=warning.- OPcache:
opcache.enable=1,opcache.memory_consumption=256,opcache.jit=1255. php artisan route:cache.php artisan view:cache.composer install --optimize-autoloader --no-dev.

Level 2 — Database (biggest wins)
- Kill N+1 with
->with(['author', 'tags']). - Add indexes on every column you filter or join on.
select()only the columns you use.- Chunk large jobs with
chunkById(500).
Level 3 — Cache aggressively
- Cache expensive queries with
Cache::remember. - HTTP cache marketing pages (
Cache-Control: public, s-maxage=3600). - Redis for cache + session + queue.
Level 4 — Queues
- Move email, PDF, webhooks, and image work to queues.
- Run Horizon under supervisor for high throughput.

Level 5 — Octane
- Switch to
laravel/octanewith FrankenPHP or Swoole. - Fix shared-state bugs — no
staticmutation across requests. - Expect 3–8x RPS improvement.
Level 6 — Frontend
- Preload the LCP image.
- Use Vite
manualChunksto split vendor code. - Reserve image dimensions to keep CLS below 0.1.
The results
Metric — Before — After
p95 API latency — 610 ms — 78 ms
Marketing LCP — 3.4 s — 1.1 s
RPS on 2-vCPU — 420 — 4,100

FAQ
Do I need Octane? If your traffic exceeds ~500 RPS or your TTFB is above 300 ms, yes.
Redis or Memcached? Redis — queues and pub/sub for free.
Key takeaways
- Laravel performance optimization starts with basic config tweaks.
- Database indexing and eager loading offer the biggest speed gains.
- Aggressive caching with Redis drastically reduces load on your app.
- Offload heavy tasks to queues for responsive user experiences.
- Laravel Octane delivers significant RPS improvements for high-traffic apps.
- Frontend optimizations ensure a smooth user experience.
Boosting Laravel Application Speed: The Impact of Performance Optimization
Laravel performance optimization is crucial for delivering a fast, responsive web application that delights users and ranks well in search engines. A sluggish Laravel application can lead to increased bounce rates, lost conversions, and ultimately, a negative perception of your brand. By systematically addressing bottlenecks from the framework level to the database and frontend, developers can unlock remarkable speed improvements. These optimizations often involve strategic caching, efficient database interactions, judicious use of background queues, and leveraging modern PHP execution environments. The goal is to maximize throughput, minimize latency, and provide a seamless experience even under heavy load.
Real-world example
A high-traffic e-commerce platform built on Laravel was experiencing significant performance bottlenecks during peak sales events. The average response time for product pages was over 1.2 seconds, and API latency for checkout processes often spiked above 800ms. After implementing a phased Laravel performance optimization strategy, the results were transformative.
Optimization Phases & Outcomes
- Phase 1: Database & Caching Adjustments (Week 1)
- Actions: Added missing database indexes, implemented eager loading across all relationship-heavy queries, and aggressively cached product detail pages for 5 minutes using
Cache::remember. Switched session and cache drivers to Redis. - Impact: Average product page load time dropped to 650ms. API latency for core functions decreased to 450ms.
- Phase 2: Queue Offloading (Week 2)
- Actions: Migrated image processing, order confirmation emails, and third-party webhook notifications to Laravel Queues, running with Redis as the driver and Horizon for management.
- Impact: Checkout API latency further reduced to 300ms, as the main request no longer waited for these background tasks. Server CPU utilization dropped by 15%.
- Phase 3: Octane & Frontend (Week 3)
- Actions: Deployed Laravel Octane with FrankenPHP, enabling persistent application memory. Implemented advanced frontend optimizations: LCP image preloading, Vite's
manualChunksfor vendor splitting, and explicit image dimensions to prevent layout shifts. - Impact: P95 API latency plummeted to 78ms. Marketing LCP improved from 3.4s to 1.1s. The server's Requests Per Second (RPS) soared from an average of 420 to over 4,100 on a 2-vCPU instance, effectively handling ten times the previous traffic with lower resource usage.
This phased approach to Laravel optimization demonstrates how significant gains can be achieved through a combination of well-understood techniques, leading to a much more scalable and user-friendly application.
Step-by-step implementation
Optimizing your Laravel application for peak performance involves a systematic approach across various layers of your stack. Here's how to implement some of the key optimizations:
- Enable OPcache for PHP Performance: Configure PHP's OPcache to store precompiled script bytecode in shared memory, avoiding recompilation on each request.
; php.ini
opcache.enable=1
opcache.memory_consumption=256
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=10000
opcache.validate_timestamps=0
opcache.jit=1255 ; For PHP 8.0+- Optimize Autoloader and Configuration for Production: Run Composer in optimized mode and cache Laravel's routes and views. This reduces file lookups and parsing on every request.
composer install --optimize-autoloader --no-dev
php artisan optimize
php artisan route:cache
php artisan view:cache- Implement Eager Loading for Database Relations: Prevent N+1 query problems by telling Laravel to load all related models in a single query. Always use
->with()when accessing relationships in loops or collections. - Add Database Indexes Liberally: Identify frequently queried columns, columns used in
WHEREclauses,ORDER BYclauses, orJOINconditions, and add database indexes to them. UseEXPLAINto analyze slow queries. - Utilize Redis for Caching, Sessions, and Queues: Replace file-based caching and session drivers with Redis for significant speed improvements and better scalability. Configure Laravel to use Redis in
config/cache.php,config/session.php, andconfig/queue.php. - Offload Long-Running Tasks to Queues: Move any operation that doesn't need an immediate response (e.g., sending emails, generating reports, processing images) to a background queue. Configure a queue worker and use
php artisan horizonfor robust queue management. - Adopt Laravel Octane for Server-Side Performance: For high-throughput applications, switch to Laravel Octane with a server like FrankenPHP or Swoole. Expect to review your application for shared-state bugs, as objects persist across requests.
Common pitfalls and how to fix them
Optimizing Laravel performance can sometimes lead to new challenges or overlooked issues. Being aware of these common pitfalls can save significant debugging time.
- Pitfall: Over-caching, leading to stale data or complex cache invalidation logic.
Fix: Implement clear cache policies with appropriate TTLs (time-to-live) and use cache tags for more granular invalidation when related data changes. Consider event-driven cache invalidation.
- Pitfall: Ignoring
OPcachewarming, resulting in initial slow requests after deployment or server restart.
Fix: Use an OPcache warming script post-deployment (e.g., opcache:compile in Laravel Zero) or ensure consistent traffic hits all critical paths to populate the cache.
- Pitfall: Not optimizing images or other static assets, despite server-side efforts.
Fix: Implement image optimization pipelines, use modern formats like WebP, and lazy-load non-critical images. Serve all static assets from a CDN for faster delivery.
- Pitfall: Shared-state issues when transitioning to Laravel Octane or similar server-persisting environments.
Fix: Thoroughly review your application for global state modifications, static property assignments, or container binding changes that are not reset between requests. Ensure all request-specific state is properly handled within the request lifecycle.
- Pitfall: Excessive logging in production
APP_DEBUG=falsebutLOG_LEVEL=debug.
Fix: Always ensure LOG_LEVEL is set to warning or error in production environments. Use dedicated logging services like Sentry or Bugsnag for structured error reporting instead of verbose file logging.
- Pitfall: Ignoring frontend performance metrics like LCP, CLS, and FID.
Fix: Regularly audit your frontend with Lighthouse or PageSpeed Insights. Prioritize optimizing critical rendering path, ensuring proper image dimensions, and asynchronously loading third-party scripts.
When to use this vs. alternatives
Laravel performance optimization techniques are primarily focused on the PHP application layer. While other solutions exist, they often target different aspects of the web stack.
Feature — Laravel Performance Optimization (Application Layer) — CDN (Content Delivery Network) — Server-side Rendering (SSR) in other frameworks — Database Sharding / Replication
Primary Goal — Reduce application execution time, improve backend latency — Reduce static asset load times, distribute content globally — Reduce initial load time for SPA; SEO friendly — Improve database read/write performance, scalability
Applicability — Dynamic content, API responses, CPU-bound tasks — Static assets (images, CSS, JS), downloadable files — Frontend-heavy applications (React, Vue) — High-volume transactional data, large datasets
Key Benefits — Faster PHP processing, efficient database queries, higher RPS — Lower latency for users worldwide, reduces server load — Faster Time To First Byte (TTFB), better SEO — Handles massive data loads, prevents single point of failure
Limitations — Does not directly optimize static asset delivery; database bottlenecks — Does not optimize backend logic or database queries — Adds complexity, requires server environment for rendering — Complex to implement and manage; eventual consistency issues
When to Choose — Your application's backend is slow, API endpoints lag, N+1 queries rampant, high server CPU usage. — You have many static assets, global user base, or need to reduce origin server load. — Building a Single Page Application (SPA) where initial page load and SEO are critical. — You have a single database server struggling with reads and/or writes under heavy load.
FAQ
How does caching improve Laravel performance? Caching stores the results of expensive operations, like database queries or complex computations, in memory or a fast storage system (e.g., Redis) so they can be retrieved quickly without re-executing the original process. This significantly reduces response times.
What is the "N+1 problem" in Laravel and how do I fix it? The N+1 problem occurs when fetching a collection of models and then iterating through them to load a related model for each item individually, resulting in N+1 database queries (1 for the collection, N for the relationships). Fix it by using eager loading with the ->with() method.
Why is APP_DEBUG=false so important for production? Setting APP_DEBUG to false in production disables detailed error messages that could expose sensitive application information to users and reduces overhead related to debug logging and asset compilation. It's a critical security and performance setting.
What is Laravel Octane and how does it speed up applications? Laravel Octane is a first-party package that supercharges your Laravel application by running it on high-performance PHP servers like Swoole or FrankenPHP. These servers keep your application in memory between requests, eliminating the bootstrap phase on each request, leading to dramatically faster response times and higher throughput.
Should I use Redis or Memcached for caching in Laravel? While both are excellent caching solutions, Redis is generally preferred in Laravel ecosystems. Beyond caching, Redis offers persistent data structures, publish/subscribe messaging, and can also serve as a high-performance queue driver, making it a more versatile choice for a Laravel application's infrastructure.
Related concepts
- Database Indexing Strategies
- Content Delivery Networks (CDNs)
- PHP-FPM Configuration
- Load Balancing and Scaling Laravel Applications
- Core Web Vitals Optimization