way to batch importing to stay under the max_input_vars

way to batch importing to stay under the max_input_vars

crcucbcrcucb Posts: 104Questions: 35Answers: 0

I used https://editor.datatables.net/examples/extensions/import as a reference to create an import process, however I am getting, "Too many rows edited at the same time (tech info: max_input_vars exceeded)."

I may not have the ability to expand max_input_vars because of where the server is hosted.
I am trying to find a workaround without retooling a bunch of stuff.

Is there a way to auto-batch through the data being uploaded so it only uploads X number of records at a time?

Answers

  • allanallan Posts: 65,277Questions: 1Answers: 10,821 Site admin

    Hi,

    There is no built in option for that specifically I'm afraid. What would need to happen is to use ajax as a function to split the payload over multiple requests (probably in a queue rather than firing them all off at once) before then finally calling the callback function to tell Editor that it has been updated. You'd need to keep a hold of the responses from the server to build up the data array as well. Using this route you may wish to do a validation submit before a write submit, to make sure all of the data is valid before writing anything to the db.

    That all said, there is another option - ajax.submitAs. You could have the client submit the entire data set as the request body, rather than as parameters.

    The upshot is that on the server-side you would need to use something like:

    parse_str( file_get_contents('php://input'), $postData );
    $json = json_decode($postData, true);
    

    Then do ->process($json) rather than ->process($_POST).

    The second option is definitely easier! Depending on how much data you are submitting you might need to watch out for post_max_size and also processing duration though.

    Allan

  • crcucbcrcucb Posts: 104Questions: 35Answers: 0

    Is there a working example of utilizing ajax.submitAs and the PHP processing?

  • allanallan Posts: 65,277Questions: 1Answers: 10,821 Site admin

    I'm afraid there isn't, no. However, the edit.php script in this example (which you would need to access from the download package, it isn't available on that page), uses the php://input method to read a request body.

    It should be just as I've described - use:

    ajax: {
      submitAs: 'json',
      url: ...
    }
    

    And then the PHP code from above. Possible you might need to check for $postData being empty before attempting to JSON decode it.

    Allan

Sign In or Register to comment.