phpajaxlaravelazureweb-applications

Laravel PHP Request Size on Azure WebApp


I have two Web Apps created in Azure - dev and prod. Both on Linux. They have exactly the same setups, same env variables etc. I encountered a strange bug while sending a request from my FrontEnd to the BackEnd. Both apps use Laravel 10.

It looks like a file/variable size limit on prod - but I cannot recreate the same issue on Dev.

While sending a big form request (25kB) from FrontEnd to Backend my data gets cut. Data is being sent using AJAX, and before sending I debug by puting console.log with the full data variable. What I'm getting in browsers console is full data as it should be.

AJAX request:

console.log('order data: ' + JSON.stringify(newOrder));
console.log('url: ' + promiseUrl);

promise = $.ajax({
    _token: token,
    method: 'POST',
    type: 'POST',
    url: promiseUrl,
    data: newOrder,
    dataType: 'json'
})

On my backend, it goes through an empty Laravel Form Request that has authentication set to return true, like below:

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UpdateOrderRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, mixed>
     */
    public function rules()
    {
        return [
            //
        ];
    }
}

What I receive in my controller - at the very beginning using this code:

public function update(UpdateOrderRequest $request){

    $validated = $request->all();
    Log::channel('order')->info('Order data:');
    Log::channel('order')->info($validated);

}
   

is the data, but it's finished after around 42000 characters in 1620 lines.

The some code, same setup and similar data doesn't cut off even with 30kB of data, with around 48000 chars and 1640 lines on dev.

What is the difference between them and what am I missing?

IIS is supposed to have max 28MB of request data, PHP even if set to 2MB should be able to pass 25-30KB without issues right?

I tried changing the upload_max_filesize, max_post_size and I don't see any results.


Solution

  • For future reference - if someone encounters a similar error.

    In my case it was either max_input_vars or max_input_nesting_level.

    I changed them to max_input_vars = 10000 and max_input_nesting_level = 10 and now it works. Still have no clue why it was different between dev and prod.

    If you need to do the same in your azure web app you need to do as follows:

    1. Create an .ini file in /home/site/ini folder. You can do this using FTP, Kudu or SSH. My file was named .user.ini
    2. In that ini file, specify the settings separating them with returns. You can use nano in SSH, file editor via FTP or echo through Kudu.
    3. Save the file and go to your WebApp in Azure. On the left, select Setting>Environment variables. Then choose App Settings tab.
    4. Here you need to add new Setting with a name PHP_INI_SCAN_DIR and value /usr/local/etc/php/conf.d:/home/site/ini. This value ensure that all inis are loaded from the usual path first, and then what you added in your home/site/ini.

    Now after restarting you webapp - new settings should be loaded from your ini file :)