You wake up to a pager alert, tail the PHP-FPM error log, and stare at the exact fatal error every WordPress engineer eventually memorizes:
PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 20480 bytes) in /var/www/html/wp-includes/class-wpdb.php on line 2316
When teams search for allowed memory size of 268435456 bytes exhausted wordpress at two in the morning, two details routinely send them down the wrong rabbit hole. First, 268435456 bytes is exactly 256 megabytes (256 * 1024 * 1024 bytes, or 256 MiB, which PHP maps from memory_limit = 256M). Second, tried to allocate 20480 bytes doesn’t mean a 20 KB query broke your server, and wp-includes/class-wpdb.php is almost never the culprit.
That 20 KB allocation was just the final brick dropped onto a 255.98 MB pile. WordPress core files sit at the bottom of the trace because plugins constantly call wpdb, formatting.php, or functions.php to allocate strings and arrays. Blaming the file in the log is like blaming the last drop of water for overflowing a bucket a leaky plugin filled over four seconds.
Reading the byte ceiling before touching a config file
Convert the byte figure first. The ceiling printed in the error tells you which layer of your PHP 8.3 or 8.4 stack is capping memory before you waste time editing the wrong file.
| Error Byte Count | PHP memory_limit | What Usually Triggers This Ceiling |
|---|---|---|
| 33554432 | 32M | Legacy shared-hosting defaults or minimal containers where WordPress core barely boots before the theme loads. |
| 67108864 | 64M | Default Multisite frontend cap (WP_MEMORY_LIMIT) or starved FPM pools failing once a page builder or multilingual plugin activates. |
| 134217728 | 128M | Stock Debian and Ubuntu php.ini default on PHP 8.3 and 8.4; commonly hit during WooCommerce checkout, image resizing, or moderate autoload bloat. |
| 268435456 | 256M | Default WordPress WP_MAX_MEMORY_LIMIT for admin screens and many managed FPM pools; hit by bloated wp_options autoload rows, stuck Action Scheduler queues, or unpaginated queries. |
| 536870912 | 512M | Raised ceilings that only fail when something is genuinely broken: infinite hook recursion, massive imports, or unpaginated queries across tens of thousands of rows. |
A healthy WordPress frontend request on PHP 8.3 or 8.4 peaks between 20 MB and 65 MB even on a busy WooCommerce store. Crossing 256 MB on a normal page render isn’t a sign that you need bigger hardware; it means something is loading junk on every boot or leaking objects mid-request.
Why editing WP_MEMORY_LIMIT in wp-config.php silently fails
Most troubleshooting posts tell you to drop define('WP_MEMORY_LIMIT', '512M'); into wp-config.php and reload. Half the time you save, refresh, and see the exact same 268435456 bytes exhausted crash. One of five precedence traps quietly overruled your edit without throwing a warning.
Placement below wp-settings.php
wp-config.php executes top to bottom as plain PHP. Near the bottom sits require_once ABSPATH . 'wp-settings.php';, which runs wp_initial_constants() to define WP_MEMORY_LIMIT if unset and immediately calls wp_raise_memory_limit(). Anything pasted below that line executes too late. Always place memory constants above the “stop editing” marker:
define( 'WP_MEMORY_LIMIT', '256M' );
define( 'WP_MAX_MEMORY_LIMIT', '512M' );
/* That's all, stop editing! Happy publishing. */
require_once ABSPATH . 'wp-settings.php';
WP_MEMORY_LIMIT ignores /wp-admin/ and background jobs
WP_MEMORY_LIMIT only covers frontend traffic. Whenever you load /wp-admin/, fire admin AJAX, resize images, or run WooCommerce and Action Scheduler queues, WordPress calls wp_raise_memory_limit( 'admin' ), which reads WP_MAX_MEMORY_LIMIT instead. That constant defaults to 256M. Raising WP_MEMORY_LIMIT to 512M while leaving WP_MAX_MEMORY_LIMIT untouched keeps admin screens pinned at 256 MB unless PHP’s baseline limit is already higher, since WordPress won’t lower an existing server ceiling.
PHP-FPM php_admin_value hard locks
WordPress adjusts memory at runtime via ini_set( 'memory_limit', ... ). Inside a PHP-FPM pool file like /etc/php/8.3/fpm/pool.d/www.conf or /etc/php/8.4/fpm/pool.d/www.conf, one prefix decides whether WordPress can change that limit:
; Allows WordPress ini_set() to raise memory_limit
php_value[memory_limit] = 256M
; Hard-locks the worker at 256M; ini_set() silently returns false
php_admin_value[memory_limit] = 256M
Managed hosts and control panels love php_admin_value[memory_limit]. When it’s active, ini_set() quietly returns false and wp-config.php can’t move the cap until you edit the pool file and reload php8.3-fpm or php8.4-fpm.
LiteSpeed and Apache .user.ini precedence delays
On PHP-FPM behind Nginx or Apache, or LiteSpeed LSAPI, adding php_value memory_limit 512M to .htaccess either does nothing or throws a 500 error because mod_php isn’t loaded. Those stacks read .user.ini instead. Two traps catch operators here: a forgotten .user.ini in the webroot or a parent folder overrides global php.ini while still losing to FPM’s php_admin_value, and PHP caches .user.ini reads for user_ini.cache_ttl seconds (300 by default). Edit .user.ini, refresh immediately, and you’ll hit the old 256M wall for five minutes unless you reload PHP-FPM or restart detached LiteSpeed workers.
CLI php.ini versus FPM php.ini
Linux packages split CLI and web configs: /etc/php/8.4/cli/php.ini defaults to memory_limit = -1 (unlimited), while /etc/php/8.4/fpm/php.ini sits at 128M or 256M. Running php -r 'echo ini_get("memory_limit") . PHP_EOL;' over SSH queries the CLI binary and misleads you into thinking memory is uncapped. Inspect the FPM directories directly:
grep -rn "memory_limit" /etc/php/8.4/fpm/ /etc/php/8.3/fpm/
wp eval 'echo "CLI limit: " . ini_get("memory_limit") . PHP_EOL;'
To verify what web workers actually enforce, check Tools, Site Health, Info, Server inside WordPress rather than trusting CLI output.
The real memory hogs on PHP 8.3 and 8.4 in 2026
PHP 8.3 and 8.4 didn’t make WordPress hungrier for RAM—packed arrays and OPcache interned strings are tighter than older engines. When a modern worker crosses 256 MB, you’re facing database serialization bloat loaded on boot or a userland memory leak piling up inside PHP arrays and object graphs.
Bloated wp_options autoload rows after the WordPress 6.6 shift
On every uncached request, WordPress calls wp_load_alloptions() before the theme boots, pulling every autoloaded row from wp_options into RAM. A clean site autoloads under 300 KB. On older WooCommerce stores, autoloaded rows often swell past 15 MB to 40 MB of raw text, expanding into 100+ MB of PHP zvals once unserialized.
Old guides miss half the bloat on WordPress 6.6 and newer. Core replaced the legacy 'yes' and 'no' flags with 'on', 'auto-on', 'auto', 'off', and 'auto-off' via wp_autoload_values_to_autoload(). Querying only WHERE autoload = 'yes' blinds you to newer options marked 'on' or 'auto'. Run these two SQL queries instead:
SELECT
ROUND(SUM(LENGTH(option_value)) / 1024 / 1024, 2) AS total_autoload_mb,
COUNT(*) AS autoload_row_count
FROM wp_options
WHERE autoload IN ('yes', 'on', 'auto-on', 'auto');
SELECT
option_name,
autoload,
ROUND(LENGTH(option_value) / 1024, 1) AS size_kb
FROM wp_options
WHERE autoload IN ('yes', 'on', 'auto-on', 'auto')
ORDER BY LENGTH(option_value) DESC
LIMIT 20;
Those top twenty rows usually expose expired _transient_* leftovers missing TTLs, bloated cron arrays stuffed with failed events, giant redirect lists, or GeoIP tables shoved into wp_options. Deleting dead transients and switching oversized non-essential rows to autoload = 'off' routinely drops peak request memory by 60 to 100 MB immediately.
Infinite hooks, WooCommerce HPOS batches, page builder JSON, and unpaginated queries
When wp_options sits safely under 1 MB, the bug lives in code. Four patterns cause most 256 MB crashes on live sites:
First, recursive hook loops. A save_post callback calls wp_update_post() without unhooking itself via remove_action(), or a shortcode invokes apply_filters( 'the_content', ... ) on content containing itself. PHP 8.3’s zend.max_allowed_stack_size catches raw C-stack overflow earlier, yet iterative loops appending to static caches still sprint straight into the 256 MB heap wall.
Second, WooCommerce High-Performance Order Storage (HPOS) paired with Action Scheduler. HPOS moves orders into dedicated wp_wc_orders tables, which speeds up lookups—until an outdated shipping or ERP plugin forces HPOS compatibility mode (dual-syncing every write back to legacy post meta) while wp_actionscheduler_actions backs up. Oversized action_scheduler_queue_runner_batch_size filters or stuck claims holding huge JSON payloads in args force a single cron runner to hydrate hundreds of full WC_Order objects at once until PHP crashes.
Third, page builder JSON revisions. Elementor (_elementor_data), Divi, Bricks, and complex block layouts serialize full page trees into wp_posts and wp_postmeta. Without WP_POST_REVISIONS capped in wp-config.php, editing a long landing page 100 times stores 100 copies of a 1.5 MB JSON tree. Opening revision diffs or running REST exports drags tens of megabytes of JSON into PHP strings at once. Treating revision caps and draft pruning as part of disciplined editorial content hygiene keeps publishing workflows clean while stopping postmeta tables from choking PHP workers.
Fourth, unpaginated WP_Query calls with 'posts_per_page' => -1. It runs fine with 80 staging posts and blows up production once the catalog hits 35,000 products. By default, WP_Query hydrates every column into a WP_Post object and primes full post meta and term caches inside $wp_object_cache. Even when you only want IDs, that query can burn 300 MB. Paginate in chunks and disable unnecessary caches:
$query = new WP_Query( [
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => 500,
'paged' => $page,
'fields' => 'ids',
'no_found_rows' => true,
'update_post_meta_cache' => false,
'update_post_term_cache' => false,
] );
Isolating the culprit in two minutes without breaking live traffic
Never deactivate plugins one by one on a live store—killing payment gateways or caching plugins wrecks active carts. You can pinpoint the offender over SSH in two minutes without changing database state.
Start with WP-CLI to list active plugins and inspect both modern and legacy autoload rows:
wp plugin list --status=active --fields=name,version,update
wp option list --autoload=on --fields=option_name,size_bytes --orderby=size_bytes --order=desc --format=table
wp option list --autoload=yes --fields=option_name,size_bytes --orderby=size_bytes --order=desc --format=table
Next, use the wp-cli/profile-command package (wp package install wp-cli/profile-command) to profile the failing URL in an isolated CLI process, passing --skip-plugins to test suspects safely while visitors stay untouched:
wp profile stage --url=https://example.com/problem-page/
wp profile hook --url=https://example.com/problem-page/ --spotlight
wp profile stage --url=https://example.com/problem-page/ --skip-plugins=suspect-plugin
If the crash only triggers inside an authenticated PHP-FPM session, drop a tiny must-use plugin at wp-content/mu-plugins/mem-trace.php gated behind a private query token. Regular traffic skips it entirely, while your test request logs exact memory deltas across lifecycle hooks:
<?php
if ( ( $_GET['mem_diag'] ?? '' ) !== '7f9c2a1b' ) {
return;
}
$log_mem = static function ( string $stage ): void {
$real_peak = round( memory_get_peak_usage( true ) / 1048576, 2 );
$emalloc = round( memory_get_usage( false ) / 1048576, 2 );
error_log( sprintf( '[MEM-TRACE] stage=%s emalloc=%sMB real_peak=%sMB', $stage, $emalloc, $real_peak ) );
};
foreach ( [ 'muplugins_loaded', 'plugins_loaded', 'init', 'wp_loaded', 'wp', 'template_redirect', 'shutdown' ] as $hook ) {
add_action( $hook, static function () use ( $log_mem, $hook ): void {
$log_mem( $hook );
}, 999 );
}
Passing true to memory_get_peak_usage( true ) matters: false measures only PHP’s internal emalloc() accounting, while true measures real OS page chunks reserved by the Zend Memory Manager—the exact number that trips memory_limit. If plugins_loaded logs 22 MB and init jumps to 215 MB, you just eliminated your theme and templates in ten seconds. That same stage-by-stage tracing mindset applies across the wider PHP CMS ecosystem, including debugging PHP fatal errors during Drupal 7 to Drupal 11 migrations where runaway entity caches blow out worker RAM identically.
Why cranking memory_limit to 2048M on a 4 GB VPS is a trap
Once engineers clear a php_admin_value lock, the knee-jerk reaction is setting memory_limit = 2048M so the error vanishes. On a 4 GB VPS, that turns one broken endpoint into a full-server blackout.
Check the RAM math on a 4 GB machine. Usable memory is roughly 3.8 GiB. MariaDB takes 1.0 to 1.5 GB for its InnoDB buffer pool and connection buffers. Nginx, Redis, systemd, and Linux page cache claim another 500 to 700 MB, leaving roughly 1.6 to 2.0 GB total for your entire PHP-FPM pool.
Remember that memory_limit applies per PHP-FPM worker, not globally. With pm.max_children = 20 and memory_limit = 256M, a leaky report dies cleanly inside one worker, returns a 500 to that single caller, and leaves nineteen workers serving shoppers normally. Raise it to 2048M and you remove that circuit breaker. Three concurrent bots or admins hit the broken URL, each worker balloons past 900 MB, physical RAM evaporates, and the Linux OOM killer steps in. Run dmesg -T after one of those blackouts and you’ll usually see the kernel killed mysqld because it held the largest resident footprint—knocking every site offline with 502 errors and forcing InnoDB crash recovery.
Never size memory ceilings in isolation from worker concurrency. Measure real per-worker Proportional Set Size (PSS) before choosing pool limits, following our guide to fixing PHP-FPM pm.max_children exhaustion and measuring real worker PSS. On a 4 GB VPS, keep frontend memory_limit at 256M and reserve 512M strictly for WP_MAX_MEMORY_LIMIT or isolated CLI jobs.
And be honest if memory firefighting happens every month. Often the culprit isn’t one rogue plugin—it’s fifty overlapping extensions bolting an internal document hub or multi-department ERP onto WordPress, which usually traces back to common structural mistakes teams make when selecting a CMS platform early on. When stateful employee workflows and deep permission matrices permanently blow your PHP memory budget, evaluating open-source intranet CMS alternatives beats buying bigger VPS nodes to feed leaky workers.
Practical answers to recurring PHP memory questions
Does upgrading from PHP 8.2 to PHP 8.3 or 8.4 increase WordPress memory usage?
No. PHP 8.3 and 8.4 trim memory overhead across several internal paths compared to older releases. If 268435456 bytes exhausted appears right after an upgrade, check whether the new PHP-FPM package installed a fresh php.ini or pool override resetting your limit, or whether an outdated plugin is spamming deprecation warnings into an in-memory logger.
Why does the error blame wp-includes/class-wpdb.php when a plugin caused the leak?
PHP prints the file where the final allocation failed, not what consumed the previous 255 MB. Because plugins route database and formatting calls through core helpers, the fatal trace almost always terminates inside wp-includes/. Use WP-CLI profiling or hook-level memory_get_peak_usage(true) logging to catch the real allocator.
How much autoloaded data in wp_options is too much?
Stay under 800 KB, and audit immediately once total autoloaded bytes cross 1 MB. WordPress 6.6+ flags Site Health warnings around 800 KB because every row matching autoload IN ('yes', 'on', 'auto-on', 'auto') loads on uncached boots and expands into much larger PHP arrays in RAM.
Should I set memory_limit to -1 in PHP-FPM so WordPress stops crashing?
Never set memory_limit = -1 on web-facing PHP-FPM pools. Removing the per-worker ceiling lets one infinite hook or unpaginated query consume all host RAM until the Linux OOM killer terminates MariaDB or PHP-FPM server-wide. Reserve unlimited memory strictly for monitored CLI maintenance scripts.