Insights

php -i Shows 512M but the Site Still Hits memory_limit? CLI and FPM Differ

November 10, 2026
0:00
The site keeps logging Allowed memory size of 134217728 bytes exhausted. You SSH in, run php -i | grep memory_limit, and it says 512M. So which one is lying? Neither. The php command in your shell and the PHP that serves your website are usually separate processes that read separate configuration. Only one of them handles the web request. The error message already tells you the real limit. 134217728 bytes is exactly 128M, and 268435456 would be 256M. If the byte count in the log doesn't match what php -i reports, you've already proved the web process runs with a different value. Everything below is about finding where that value comes from, then confirming it from the web side.
PHP runs under a SAPI (Server API), which is the interface between PHP and whatever starts it. When you type php in a terminal, you get the CLI SAPI. When Nginx or Apache hands a request to PHP-FPM, the code runs under the FPM SAPI. They're the same language, but they start differently and usually load different config files. On Debian and Ubuntu packages this split is easy to see. The CLI reads /etc/php/<version>/cli/php.ini, and FPM reads /etc/php/<version>/fpm/php.ini. If you edit the CLI file, the website never sees the change. FPM then adds layers the CLI ignores completely:
  • Pool configuration. A pool is a group of FPM workers with its own user, socket, and settings. A pool file can force a value with php_value[memory_limit] or php_admin_value[memory_limit].
  • .user.ini files. These sit in the document root or its subdirectories, and FPM and CGI read them per directory. The CLI does not.
  • The script itself. Code can call ini_set('memory_limit', ...) at runtime. WordPress does this with its WP_MEMORY_LIMIT constant.
Version mismatch is another common trap. The php on your PATH might be 8.3 while the site's pool runs 8.1, so you end up reading a php.ini the site never loads. On the support desk, this split is a frequent reason someone says they already raised the limit and nothing changed. They did raise it, just for the wrong process.
LayerRead by CLIRead by FPMCan ini_set() or .user.ini override it
cli/php.iniYesNoYes
fpm/php.ini and fpm conf.dNoYesYes
Pool php_value[memory_limit]NoYesYes
Pool php_admin_value[memory_limit]NoYesNo
.user.ini in the docrootNoYesYes, by ini_set()
The php_admin_value row explains a lot of confusing cases. When a pool sets memory_limit that way, no .user.ini, no WordPress constant, and no plugin can raise it. The only fix is in the pool file.
Start with read-only commands. None of these change anything. The FPM paths assume the Debian/Ubuntu layout. Control panels and RHEL-family systems keep FPM configs elsewhere, so adjust the paths if ls finds nothing.
BASH
# CLI side: binary, version, loaded php.ini, effective value
which php
php -v
php --ini
php -i | grep -i '^memory_limit'

# FPM side (Debian/Ubuntu layout; paths differ on control panels)
ls -d /etc/php/*/fpm 2>/dev/null
grep -Rn 'memory_limit' /etc/php/*/fpm/ 2>/dev/null

# Which FPM socket or port the web server sends this site to
grep -Rn 'fastcgi_pass' /etc/nginx/ 2>/dev/null
grep -Rn '^listen' /etc/php/*/fpm/pool.d/ 2>/dev/null
Read the results in this order. php --ini shows which php.ini the CLI loads and which extra .ini files it scans. The php -i line prints two values, the local value and the master value. If those differ, something like a -d flag or an alias is changing the CLI value. The recursive grep over the FPM directory catches both the FPM php.ini and any pool file that sets memory_limit. If a pool line shows php_admin_value[memory_limit] = 128M, that's probably your answer. The fastcgi_pass and listen lines tie it all together. Match the socket path in the Nginx vhost to the listen line in a pool file. That tells you which PHP version and which pool actually serve this domain. On Apache with proxy_fcgi, look for the SetHandler line that points at the socket. On LiteSpeed, PHP usually runs as lsphp rather than FPM, so the file locations differ. The web-side check in the next section works the same way on all of them.
Config files tell you what should apply. A request through the web server tells you what does apply after every layer has run. The most reliable check is a small, temporary PHP file in the site's document root, fetched over HTTP like a visitor would. Security note: this file reveals server details. Give it a name nobody would guess, and delete it as soon as you're done. Don't use phpinfo() for this, because it exposes far more than you need.
PHP
<?php
// Temporary diagnostic file. Use an unguessable name and delete it after testing.
header('Content-Type: text/plain');
echo 'SAPI: ' . php_sapi_name() . PHP_EOL;
echo 'PHP version: ' . PHP_VERSION . PHP_EOL;
echo 'Loaded php.ini: ' . php_ini_loaded_file() . PHP_EOL;
echo 'Scanned ini files: ' . php_ini_scanned_files() . PHP_EOL;
echo 'memory_limit: ' . ini_get('memory_limit') . PHP_EOL;
echo 'user_ini.filename: ' . ini_get('user_ini.filename') . PHP_EOL;
echo 'user_ini.cache_ttl: ' . ini_get('user_ini.cache_ttl') . PHP_EOL;
Save it as something like mlcheck-7f3a9c.php and request it with curl or a browser. Under FPM, the SAPI line should read fpm-fcgi. If the PHP version differs from what php -v showed, you've found a version mismatch. If the memory_limit here matches the byte count in your error log, you're looking at the right process. This probe shows the value at the start of a request in that directory. It doesn't show later runtime changes. If the application calls ini_set() during the request, the value can change after the probe would have read it. For WordPress, WP_MEMORY_LIMIT in wp-config.php raises the limit at runtime only when the pool allows it. If the pool uses php_admin_value, the constant has no effect. Remember that the probe only reports the directory it sits in. A .user.ini in a subdirectory, such as an admin folder, only applies to scripts in that directory and below. If the error only happens on one path, place the probe in that same directory.
Once you know which layer sets the value, change it in that layer only. If the pool uses php_admin_value, edit the pool file. If the value comes from fpm/php.ini, edit that file. Editing cli/php.ini again won't help. On control panels, the panel's PHP settings screen often writes to one of these layers for you. Use it rather than hand-editing files the panel might regenerate, and check the probe afterwards either way. FPM reads php.ini and pool files at startup, so it needs a reload. A .user.ini change doesn't need a reload, but it's cached for user_ini.cache_ttl seconds, often 300. That's why .user.ini edits can seem to do nothing for a few minutes. The steps below run in order. Test the config before reloading, because a syntax error in a pool file can stop FPM from coming back up.
BASH
# 1. Before: record the value the web request sees
curl -s 'https://example.com/mlcheck-7f3a9c.php'

# 2. After editing the FPM config: test it (binary name varies by version and distro)
sudo php-fpm8.2 -t

# 3. Reload gracefully so in-flight requests finish (service name varies)
sudo systemctl reload php8.2-fpm

# 4. After: confirm the new value from the web side
curl -s 'https://example.com/mlcheck-7f3a9c.php'

# 5. Remove the probe
rm -f /path/to/docroot/mlcheck-7f3a9c.php
If step 4 still shows the old value, the change landed in a layer that something above it overrides. It could also be a different pool or PHP version than the one serving this domain. Go back to the grep and the socket match before editing anything else. After that, load the page that used to fail and watch the site's PHP error log. If the error comes back with the new byte count, the limit is applied correctly and the script really needs more memory than you gave it. That usually points to a heavy plugin, a large import, or a query loading too much data at once. Raising the ceiling again won't fix those. Raising memory_limit doesn't make a site faster, and each FPM worker can use up to that limit, so a higher value also reduces how many workers fit in RAM. The same split works in reverse. Cron jobs and WP-CLI run through the CLI, so they use cli/php.ini. A command-line import can succeed while the same import fails in the browser. If you've recently moved a site from mod_php, also check that old php_value lines in .htaccess aren't causing errors under PHP-FPM. The practical rule: treat php -i as a report on your shell, not on your website. When memory errors don't match what you expect, convert the byte count in the log to megabytes, check which pool and PHP version serve the domain, and confirm the value through an actual web request before and after the change. If the before and after values come from the same probe on the same path, you know the fix landed where it counts.

Join My Newsletter & Get Updates!

Get notified whenever a new technical guide, server infrastructure breakdown, or personal reflection goes live, plus a curated weekly digest.