Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › caching

Laravel Performance Problems: 7 Development Mistakes and How to Fix Them

By Freedom251 Team · · 9 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A slow Laravel request is usually traceable to a small number of repeatable mistakes: too many database queries, missing indexes, repeated expensive work, uncached deployment artifacts, misplaced env() calls, unmeasured outbound I/O, or production work happening in the web request. Fix the bottleneck you can measure rather than applying every optimization at once.

This guide shows how each mistake appears, why it gets worse as traffic and data grow, and the Laravel-native remedy. The commands and behavior described follow Laravel’s current deployment, configuration, cache, and Pulse documentation; check the version-specific documentation for any label changes in your application.

As an Amazon Associate I earn from qualifying purchases.

Start with the request symptom, not a favorite optimization

Before changing an Eloquent relationship or adding a cache, capture one slow request under representative data. Record total duration, database time, query count, slowest SQL statements, outbound HTTP time, memory use, and whether the delay is repeatable. A page that takes 1.8 seconds because of SQL needs a different fix from a page that spends 1.5 seconds waiting for an external API.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A quick bottleneck map

What you observe Likely mistake First check
Query count rises with the number of rows displayed N+1 queries or careless lazy loading Count SQL statements for one request and inspect repeated relationship queries
One SQL statement becomes slower as tables grow Missing or unsuitable index, or an inefficient query shape Run the database’s execution plan against the real predicate and ordering
The same calculation or report is recomputed on every request No cache for expensive, repeatable work Measure CPU and elapsed time, then identify safe freshness and invalidation rules
First requests after deployment are slow Production configuration, route, event, or view caches were not built Review the deployment command sequence and cache status
Settings disappear or become stale after config:cache env() is being called outside configuration files Search application code for direct env() calls
Latency is dominated by remote services Unmeasured or synchronous outbound calls Use request tracing or Pulse’s slow outgoing requests card
Web workers are busy with exports, mail, or imports Heavy synchronous work or an incorrect entry point Verify the web root and move suitable jobs to a queue

Change one bottleneck at a time, repeat the same measurement, and keep the result only if the relevant metric improves. There is no universal percentage gain for these practices: the result depends on your schema, traffic, data distribution, PHP runtime, and infrastructure.

#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter | 4Pack Type C Female to A Male Cable Converter for Apple Duo 17 16 15 14 Plus,iWatch Watch 12 11 10,iPad 9 8 Air,Airpods 5 4
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

1. Allowing N+1 queries and careless lazy loading

An N+1 query occurs when Laravel retrieves a collection in one query and then executes another query for a relationship for each row. A list of 100 posts can therefore become one query for posts plus 100 author queries. Network round trips and database parsing, rather than PHP rendering, become the dominant cost, and the multiplication gets worse as the collection grows.

Typical pattern

$posts = Post::latest()->take(100)->get();

foreach ($posts as $post) {
    echo $post->author->name;
}

Accessing $post->author inside the loop lazily loads the relation when it has not already been fetched. The code looks harmless with ten rows and becomes expensive with a realistic page size or an API endpoint that returns many records.

Choose the smallest deliberate query shape

$posts = Post::with(['author:id,name'])
    ->latest()
    ->take(100)
    ->get(['id', 'author_id', 'title']);

Eager loading consolidates relationship access, while selecting only required columns limits transferred data. Include the foreign key needed to match the relation. For counts or existence checks, use relationship aggregates such as withCount instead of loading every related row. If the page needs a single related value, a join, subquery, or constrained eager load may be more appropriate than fetching a full relation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Measure the fix

  • Compare query count before and after the change for the same request and row count.
  • Inspect total database time and payload size, not only the number of statements.
  • Check for over-fetching: eager loading a large relation can replace many small queries with one memory-heavy query.
  • In development and testing, enable strict lazy-loading prevention where appropriate so accidental relation access fails early; do not assume that a development setting alone fixes production behavior.

2. Skipping indexes and query-shape review

An ORM cannot compensate for a database that must scan a growing table to satisfy every filter, join, or sort. A query that is acceptable with 5,000 rows can become a production incident with millions. Missing indexes are only part of the problem: an index that does not match the actual predicate or ordering may add write cost without improving the plan.

Rank #2
Sale
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter | USB C Dongle with 90W Max Power Delivery, 3×5Gbps USB A Data Ports, for MacBook, Dell, and More (Charger Not Included)
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Review real predicates and ordering

Start with a slow-query trace and the exact SQL generated for the request. Examine filters in where clauses, join keys, tenant or status columns, and columns used for ordering. Use the database’s execution-plan tool to verify whether the intended index is selected and whether its selectivity is useful.

$orders = Order::where('account_id', $accountId)
    ->where('status', 'open')
    ->orderByDesc('created_at')
    ->paginate(50);

For this shape, a composite index may be more useful than three unrelated single-column indexes, but the correct order depends on the database engine and data distribution. Add the index through a migration, deploy it safely for your database, and re-check the execution plan. Do not add indexes blindly: every index consumes storage and can slow inserts, updates, and deletes.

Use production evidence

Laravel Pulse can group slow queries by SQL, which helps identify recurring statements rather than isolated requests. Correlate that list with database-level plans and traffic patterns. A query that is slow only for one unusual account may need a different remedy from a query executed thousands of times per minute.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

3. Repeating expensive work without a cache

Caching is appropriate when retrieving or processing a value is CPU-intensive or takes several seconds and the result can safely be reused. Examples include a costly aggregate, a permission map shared across requests, a remote response with an accepted freshness window, or a generated report whose inputs change infrequently.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter | 85W Max PD, 2 USB 3.0 & 1 USBC Data Ports, SD/TF Card Reader, for Laptops/Mac and Other Type C Devices (Charger Not Included)
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Cache with a defined freshness contract

$summary = Cache::remember(
    "account:{$accountId}:summary",
    now()->addMinutes(5),
    fn () => $this->buildSummary($accountId)
);

The key must include every input that changes the result, such as account, locale, currency, or date range. The expiration is not a substitute for correctness: decide what happens when source data changes before the timeout.

Pick invalidation before picking a driver

  • Use explicit invalidation when a write can identify affected keys.
  • Use a short time-to-live when slightly stale data is acceptable and exact invalidation is difficult.
  • Use tags or grouped key conventions only when your chosen backend and Laravel version support the needed behavior.
  • Protect expensive cache misses from a stampede when many workers can regenerate the same value simultaneously.

Laravel documents Redis, Memcached, DynamoDB, database, and file-backed cache drivers. Choose based on deployment topology, persistence, concurrency, memory, and operational support. A cache can lower latency while introducing stale results, eviction risk, serialization cost, and another failure mode; measure hit rate and regeneration time.

4. Deploying without production caches

Laravel’s deployment guidance recommends running php artisan optimize. This prepares the framework’s production caches, while individual commands let you control the sequence and failure handling.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What each cache changes

Command Purpose What it does not fix
php artisan config:cache Combines configuration into a cached file, reducing filesystem work during boot Slow SQL, remote API latency, or incorrect application logic
php artisan event:cache Caches discovered event and listener information Listener code that performs excessive synchronous work
php artisan route:cache Caches route registration, especially useful for applications with hundreds of routes Controller execution time or uncacheable route definitions
php artisan view:cache Precompiles Blade templates Slow database calls or expensive work inside a view

Run these commands as part of a repeatable deployment, after code and dependencies are present and with the correct production environment. Confirm that the application can boot and that cached routes, views, events, and configuration match the release. If a deployment rolls back, clear or rebuild caches for the rolled-back code rather than leaving artifacts from another release.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray | Data transfer & Fast charging for MacBook, iPhone 17/16/15, iPad, Samsung Galaxy, Apple Watch
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

5. Calling env() throughout application code

The configuration cache changes how environment values are available. After php artisan config:cache, Laravel does not load the .env file during requests or Artisan commands. Direct calls to env() in controllers, services, jobs, or models can therefore return unexpected values after deployment even when local development appeared correct.

Keep environment access in configuration

// config/services.php
'payments' => [
    'endpoint' => env('PAYMENTS_ENDPOINT'),
],
// Application code
$endpoint = config('services.payments.endpoint');

Search the application for env( and move each legitimate setting into a configuration file. Read it through config() everywhere else. Rebuild the configuration cache after changing deployment variables, and verify the effective value in the same environment where the application runs. This is both a correctness fix and a deployment performance practice: the framework can read one compiled configuration artifact instead of repeatedly resolving environment files.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

6. Failing to measure slow queries and outbound calls

Changing an ORM method or adding a cache without a baseline makes it impossible to know whether the bottleneck moved, disappeared, or became a new one. Instrument the complete request: SQL duration and count, queue time, PHP execution, cache hits and misses, and time spent waiting for external services.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a concrete threshold for remote calls

Laravel Pulse documents a slow outgoing requests card with a default threshold of 1,000 milliseconds. Treat that as an observability starting point, not a universal definition of acceptable latency. A checkout request may need a stricter threshold than an overnight import.

Best Value
Sale
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display | 85W Max PD, 1 Powered USB-C 5Gbps & 2 Powered USB-A 3.0 5Gbps Data Ports, for MacBook Pro, MacBook Air, Dell and More (Black)
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

A repeatable measurement loop

  1. Capture a representative request, including its input size and authenticated tenant or account.
  2. Identify the largest contributor: SQL, PHP CPU, cache miss, or outbound I/O.
  3. Apply one targeted change, such as eager loading, an index, a bounded cache, or a queued job.
  4. Repeat the same request under comparable load and compare p50, p95, error rate, query count, and resource use.
  5. Keep the change only when the relevant user-facing metric improves without unacceptable freshness, memory, or operational trade-offs.

Pulse’s SQL grouping is useful for finding recurring slow statements, but pair application telemetry with database and HTTP-client timing. A fast local request can hide production DNS, TLS, rate-limit, or network delays.

7. Misconfiguring production entry points or doing heavy synchronous work

The web server should direct public traffic to Laravel’s public/index.php. Pointing the document root at the project directory can expose files, produce routing failures, and create operational overhead. Verify the configured root, rewrite or front-controller rules, permissions, and the PHP worker path in the actual production environment.

Move work that does not belong in the request

Exports, imports, image or document processing, bulk notifications, large data transformations, and other long-running tasks should generally be dispatched to queues when the user does not need the result immediately. Return a job identifier or status page, let workers process the task, and make the job retry-safe and observable.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
ProcessMonthlyExport::dispatch($accountId);

Do not move every operation to a queue automatically. A short validation or transaction that must complete before responding belongs in the request; a multi-minute report does not. Set worker timeouts, retry limits, concurrency, and failed-job handling deliberately, then test under realistic traffic. An incorrect entry point and overloaded synchronous workers are separate failure modes, so verify both.

Choosing the remedy by bottleneck and risk

Remedy Best fit Freshness or invalidation concern Main trade-off
Constrained eager loading, joins, or subqueries Excessive relationship queries None beyond normal database consistency Can over-fetch rows or columns and increase memory use
Purpose-built database index Repeated filters, joins, or sorts over growing tables Must be maintained as data changes Consumes storage and can slow writes
Application cache Expensive, repeatable computation or retrieval Requires expiry or explicit invalidation Can serve stale data and adds backend complexity
Config, event, route, and view caches Framework bootstrap and deployment overhead Rebuild after code or environment changes Stale artifacts can cause incorrect behavior if deployment is incomplete
Queue and worker Long-running work that need not block the response Status and retry semantics must be designed Adds asynchronous infrastructure and eventual completion

A practical order of operations

  1. Measure one slow request and classify its dominant time.
  2. Remove N+1 behavior and reduce the query shape to required fields and relations.
  3. Review the exact SQL plan and add only indexes justified by real predicates and ordering.
  4. Cache expensive repeatable work after defining key inputs, freshness, and invalidation.
  5. Add production deployment caches and ensure the release rebuilds them consistently.
  6. Move all legitimate environment reads behind configuration and rebuild the config cache when settings change.
  7. Instrument outbound calls, verify the public/index.php entry point, and queue work that should not occupy a web request.

These steps prevent a common failure pattern: using a cache to hide N+1 queries, adding indexes to compensate for a malformed query, or tuning PHP while an external request consumes the entire budget. Laravel’s performance tools are most effective when each change is tied to a measured bottleneck and its operational cost is explicit.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

cachingDatabase OptimizationDevOpsEloquentLaravelPHPweb performance

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.