Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

PHP Warning: POST Content-Length of N bytes exceeds the limit of M bytes

ErrorPHP Warning: POST Content-Length of 41943040 bytes exceeds the limit of 33554432 bytes in Unknown on line 0

Short answer

The request body is larger than post_max_size, so PHP drops it and leaves $_POST and $_FILES empty. The limit in the message is the current value, in bytes. Raise post_max_size above upload_max_filesize in a place PHP actually reads: php.ini or .user.ini, not ini_set(). Restart PHP-FPM or wait for the .user.ini cache.

  • Applies to PHP 8.3, PHP 8.4, PHP-FPM, Apache, any host that uses php.ini
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Show the two limits as the web server's PHP sees them. A CLI run can read a different php.ini, so use a temporary page served by the same stack.

    <?php
    // temporary debug page, delete after use
    echo 'post_max_size=', ini_get('post_max_size'), "\n";
    echo 'upload_max_filesize=', ini_get('upload_max_filesize'), "\n";
  2. 2Match what you see, then jump to its fix

    1. 1The limit in the warning equals post_max_size in bytes (33554432 bytes is 32M)post_max_size is smaller than the requestFix
    2. 2You changed a file, and the warning still shows the old limitThe new value is set where PHP does not read it, or has not been reloadedFix
    3. 3Uploads fail even though upload_max_filesize looks generousupload_max_filesize is larger than post_max_sizeFix

What does the error look like?

  • PHP Warning: POST Content-Length of 41943040 bytes exceeds the limit of 33554432 bytes in Unknown on line 0
  • $_POST and $_FILES are empty after a large upload

Cause 1 of 3

post_max_size is smaller than the request

1Check

The manual says that if post data is greater than post_max_size, $_POST and $_FILES are empty. Convert the number in the warning with the K, M and G shorthand rules to see which setting it is.

php -r 'echo 33554432 / 1048576, "M\n";'

2Fix

Set post_max_size higher than the biggest request you accept, with upload_max_filesize below it.

; php.ini or .user.ini
upload_max_filesize = 64M
post_max_size = 72M

3Verify

The debug page shows the new values, and the upload works.

curl -s https://example.com/phpinfo-debug.php

Confirmed by php.net

Did this fix it?

Cause 2 of 3

The new value is set where PHP does not read it, or has not been reloaded

1Check

post_max_size is INI_PERDIR, so php.ini, .user.ini or per-directory config can set it, but ini_set() at runtime cannot. .user.ini is read only with CGI or FastCGI, is looked up from the script's directory up to the document root, and is cached for user_ini.cache_ttl, 300 seconds by default.

php --ini
php -r 'echo ini_get("user_ini.cache_ttl"), "\n";'

2Fix

Put the setting in php.ini or a .user.ini in the right folder (Apache module setups use .htaccess instead), then restart PHP-FPM or wait out the cache time.

# .user.ini in the web root
upload_max_filesize = "64M"
post_max_size = "72M"
# then, with PHP-FPM
sudo systemctl restart <your-php-fpm-service>

3Verify

The debug page prints the new values.

curl -s https://example.com/phpinfo-debug.php

Confirmed by php.net

Did this fix it?

Cause 3 of 3

upload_max_filesize is larger than post_max_size

1Check

The manual says post_max_size must be larger than upload_max_filesize, and memory_limit should generally be larger than post_max_size.

php -r 'echo ini_get("post_max_size"), " ", ini_get("upload_max_filesize"), " ", ini_get("memory_limit"), "\n";'

2Fix

Keep the order upload_max_filesize < post_max_size < memory_limit.

upload_max_filesize = 64M
post_max_size = 72M
memory_limit = 256M

3Verify

A file just under the upload limit uploads.

curl -s https://example.com/phpinfo-debug.php

Confirmed by php.net

Did this fix it?

How do I stop it coming back?

  • Keep one documented set of upload limits per environment, next to the code.
  • Set the same limit in the web server if it has its own (nginx's default body limit is 1m and returns 413).
  • Show a clear message in the form when $_POST and $_FILES arrive empty.
  • Check the limit on the same stack the users hit, not only on the command line.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

A PHP upload fails or $_FILES comes back empty

$_POST and $_FILES are both empty on a large upload

A PHP upload fails for one of four reasons: the temporary directory is not writable, the whole POST is bigger than post_max_size, one file is bigger than upload_max_filesize, or there are more files than max_file_uploads.

4 causes, each with a fix

Back end

Apache returns 403 when a URL contains %3F

a request like /page%3Fname=test is refused while /page?name=test works

Recent Apache httpd blocks a rewrite when the request contains an encoded question mark (%3F) and the rewritten target has a literal ?.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.