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

This is a short guide on how to fix the following PHP warning:

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

The error message above will occur if the size of a POST request exceeds the limit that has been set in the post_max_size directive in your php.ini file.

If you look at the message carefully, you can see that the Content-Length of the POST request in this case was 77870742 bytes. That is roughly 77.87MB. This is a problem, as the post_max_size directive in our php.ini file has been set 8388608 bytes (8MB).

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

So, to sum up the issue in this particular case:

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

As you can see, it is well over the allowed limit. As a consequence of this, 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 could 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 my case, this resulted in 8M being printed to the page.

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 edit the post_max_size directive. By default, it will look like this:

post_max_size = 8M

As you can see, it is currently set to 8MB. If we wanted to change this limit to 32MB, we would simply 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 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.

PS: 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 can not 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. So, while you can change the directive using php.ini, .htaccess, httpd.conf or .user.ini, you cannot change it using ini_set.

Hopefully, this guide helped you to fix your issue!