Monday 2 February 2015

Big forms and PHP max_input_vars

Big forms and PHP max_input_vars

Recently I was working in WordPress to create a big menu, with over 75 links in it. When I created it and tried to save it got save only partially, few menu items at the end got truncated. I was not sure what happened. So then I tried to add 1 more link and it was not saving. Then I decided to check if there were any PHP errors. I found the following in the error logs:
PHP Warning: Unknown: Input variables exceeded 1000. To increase the limit change max_input_vars in php.ini. in Unknown on line 0, referer: http://mysite.com/wp-admin/nav-menus.php
Then I found out that there is a PHP setting “max_input_vars” (available since PHP 5.3.9) which limits the number of variables that PHP will process. If this value is 1000 (default is 1000) PHP will process first 1000 variables and drop the remaining. This was the reason why some menu items were saved and some not.

To solve this issue we need to increase the “max_input_vars” to a bigger number. I changed it to 2000 and it solved my problem. You might need less or more depending on your requirements.
How can we change this value? There are 2 ways. Either by changing the variable in .htaccess file or php.ini file. I will show how to change it using both the methods.
1. Change max_input_vars using .htaccess file.
If you want to change the “max_input_vars” using .htaccess file then add the following code in you .htaccess file.
1
php_value max_input_vars 2000
2. Change max_input_vars using php.ini file
Note: If you make any error in your php.ini file you site may not function properly. So make sure you know how to change it, else have someone who can do this change.
Edit your php.ini file and search for “max_input_vars“. this might look something similar to following:
1
; max_input_vars = 1000
The above line is commented, that means it will take PHP’s default value which is 1000. To change it to 2000 change that line to be:
1
max_input_vars = 2000
After this change you will have to restart your apache.

0 comments:

Post a Comment