Fix: POST Content-Length of X bytes exceeds the limit of X bytes.

In this tutorial, we are going to show you how to fix the following PHP warning:

PHP Warning: POST Content-Length of 77870742 bytes exceeds the limit of 8388608 bytes.

This error will occur if the size of a POST request is larger than the limit in your “post_max_size” directive.

If you look at the message carefully, you can see that the Content-Length of the POST request in this case was 77,870,742 bytes. That is roughly 77.87MB.

This is a problem, as the post_max_size directive in our php.ini file is 8,388,608 bytes (8MB).

By default, PHP’s post_max_size directive will be 8MB.

To sum up the issue in this particular case:

  • The size limit for a POST request is 8MB.
  • However, the size of our POST request is 77.87MB.

As you can see, it is well over the limit. Consequently, both the $_POST and $_FILES superglobal arrays will be empty.

This kind of error is particularly common with file uploads, as the size of an uploaded file can easily surpass the 8MB limit that has been set down in php.ini.

For example, a small video file could end up being 100MB or more. A form that allows the user to upload multiple files at once will also easily surpass this limit.

What is my post_max_size setting?

Here is a quick way to determine what your current post_max_size setting is:

//Print out the value of the post_max_size directive.
echo ini_get('post_max_size');

In the PHP snippet above, we printed out the value of the post_max_size setting by using the ini_get function.

In most cases, this will say “8M”.

How to increase your post_max_size setting.

To increase the size limit of your POST requests, you will need to locate your php.ini file and change the post_max_size directive.

By default, it will look like this:

post_max_size = 8M

As you can see, it is currently 8MB. If we want to change this limit to 32MB, then we will need to change the directive to:

post_max_size = 32M

PHP also allows you to specify gigabytes by using the G character:

post_max_size = 1G

In the example above, we set the maximum size of POST data to one gigabyte. Note that you can also completely disable the max size by setting the value to 0 like so:

post_max_size = 0

This will only work if you are using PHP version 5.2.12 or above. However, I would recommend that you do not disable this limit unless you’re 100% sure that you know what you are doing.

Make sure that you save the file and reload your web server after changing this directive. Otherwise, the older limit value will remain in memory.

Can I use the ini_set function to change the post_max_size directive?

The post_max_size directive cannot be changed by using PHP’s ini_set function. Therefore, using the following piece of code will not work:

//Attempting to use ini_set to change post_max_size
echo ini_set('post_max_size', '100M');

This is because the directive has a Changeable Mode Value of PHP_INI_PERDIR.

You can change this setting in a php.ini, .htaccess, httpd.conf or .user.ini file.

However, you will be unable to do so using ini_set.