Large forms not saving in SugarCRM

sugarcrmdevelopers —  July 29, 2013

I ran into an interesting issue for a client with project templates only saving the first 47 tasks. Viewing the ajax post using Firebug showed that every task was being sent over. Now it was time to debug the server side.

Within modules/Projects/SaveGrid.php I threw in some debug statements:

....
for ($i = 1; $i <= $_REQUEST['numRowsToSave']; $i++) {
// don't save any blank rows
if (isset($_REQUEST["duration_" . $i]) && ($_REQUEST["duration_" . $i] != "")) {
....
} else {
$GLOBALS['log']->fatal("Task ".$i." has no duration");
}
....

Sure enough, tasks 48 and up had no duration. So I dumped the request before the for loop to see how the parameters looked and it ends up there were 1001 parameters. None for anything related to task 48 and up. Before all of this I did a phpinfo() page to see what the environment configuration was. Previously I thought we were running into timeout or memory issues. At the bottom of the phpinfo page it showed that Suhosin was being used which is a somewhat popular project to deal with a number of known PHP flaws/security vulnerabilities (http://www.hardened-php.net/suhosin/).

Now 1001 is a weird number for someone to cutoff at so I assumed that was due to something within the app or a general programming error in Suhosin. So I searched for Suhosin 1000 parameters and found that there is a max_vars setting that many installs limit to 1000. The client then bumped this up to a much higher number (see http://anothersysadmin.wordpress.com/2012/02/16/php-5-3-max_input_var) and all tasks started to save.