Upper memory limit for PHP/Apache

Upper memory limit for PHP/Apache

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

The Upper Memory Limit for PHP/Apache

When a PHP script attempts to allocate memory beyond a certain threshold, you might expect simply raising memory_limit in php.ini or via ini_set() to resolve the issue. However, hitting a hard ceiling of approximately 1.8GB on a system with 4GB of RAM suggests that another layer is intercepting the request before it reaches the PHP interpreter's garbage collector.

In environments running XAMPP on Windows 7 (or similar 64-bit OS setups), this behavior often stems from the Apache server itself, specifically when utilizing the Multi-Processing Module (MPM). The error message Fatal error: Out of memory (allocated 1827405824) indicates that PHP tried to allocate roughly 1.8GB, but the allocation failed. This discrepancy between your configured limit and the actual failure point is the critical clue.

The Role of Apache MPM

The root cause lies in how Apache handles memory for its child processes. On Windows, XAMPP typically defaults to the MPM_Win32 or MPM_Apache2 module. While these modules are capable of handling multiple requests, they often enforce a strict per-process memory cap that is independent of PHP's internal settings.

Even if you configure memory_limit = 3000M in php.ini, Apache may be configured with a lower limit in its own configuration files. You need to inspect httpd.conf or apache2.conf. Look for directives similar to:

LimitMemoryRequest 1750M

or older configurations using:

MemCacheMaxPerProcess 1750M

If such a directive exists, it acts as an upper bound for all PHP scripts running under that Apache instance. No matter how high you set memory_limit in PHP, the server will reject requests exceeding this ceiling to prevent a single script from starving the entire process group or the machine.

Verifying the Constraint

To confirm this hypothesis, check the output of your PHP error log or access logs when the crash occurs. The allocation size reported in the error (allocated 1827405824 bytes) is suspiciously close to typical hard limits set by default configurations on Windows Apache setups.

If you are using MPM_Apache2 (which supports Prefork or Worker modes), ensure that the MaxRequestMemoryAllocation directive isn't capping your usage. More importantly, if you are running PHP-FPM behind Apache via FastCGI, the php-fpm.conf file might have a request_terminate_timeout or specific memory settings that differ from the main Apache pool.

Practical Implementation Steps

  1. Inspect Apache Config: Open httpd.conf (or apache2.conf). Search for LimitMemoryRequest. If found, increase it to match your PHP requirement (e.g., 3000M).
  2. Check PHP-FPM Pools: If using FastCGI, verify php-fpm.d/www.conf or the included pool files. Ensure no external memory caps are defined there.
  3. Restart Services: Changes to Apache configuration require a restart of the Apache service for the new limits to take effect.

Trade-offs and Considerations

Raising these limits is not without risk. Allocating nearly 2GB to a single script leaves very little room for Apache's internal overhead, other modules, or concurrent requests. If your application handles multiple users simultaneously, one "heavy" image processing task could easily exhaust the available RAM for other processes, leading to system instability or Apache crashing entirely.

For production environments handling high traffic, this approach is rarely sustainable. Instead, consider streaming large images in chunks using GD's imagecreatefromstream or optimizing the image size before processing. However, for isolated scripts on a local development machine like XAMPP where you control the entire stack, adjusting the Apache memory directives provides a clean solution without needing to rewrite the application logic.

If you are building complex media pipelines, frameworks like Laravel often abstract these concerns away. Resources regarding advanced PHP performance tuning and memory management within the Laravel ecosystem can be found at https://laravelcompany.com, which discusses strategies for handling resource-intensive tasks more gracefully in production-grade applications.

Our network