Some questions about file_get_content ('php://input') and $_ POST,post and put?

the day before yesterday, when I was doing a function, I found that the value of the page ajax was too much, so that both $_ POST and php://input were empty, which was very strange.

so I did a demo test to find out why:

    <script>

        var data = "username=111&email=222";
        for (var i = 0; i < 1750; iPP)
        {
            data += "&a" + i + "=" + i;
        }

        var xhr = new XMLHttpRequest();
        xhr.open("post", "./test.php");
        // xhr.open("put", "./test.php");
        xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        // xhr.setRequestHeader("Content-type", "application/json;charset=utf-8");
        // data = JSON.stringify({a: data});

        xhr.onload = function () { console.log(xhr.responseText); }
        xhr.send(data);

    </script>

because both method and Content-type feel right, but why can"t they get the value?

this problem occurs when I change application/json and application/x-www-form-urlencoded.

and there seems to be a critical value. You can see the print data in the loop 1650 in the code, and it will be empty for 1750 times. Test.php is just a simple

.
$content = file_get_contents("php://input");

// print_r(count($_POST) . "\n");
print_r($content);

I am a little puzzled. I keep google, Baidu for information and know the post method. There are instructions in php.ini to limit the number and size of parameters passed.

but I am the duck of file_get_contents ("php://input"), and the php input stream is not affected by php.ini profile instructions.

Why can it be done with less loops and not with more loops? Error_reporting (- 1) also reported no error, no warning, no clue.

later, I changed the request method of ajax to PUT, and found something (I didn"t understand the difference between post and put at this time)

warning

temporary1749

PHP


bug

apacheerror_log

Warningajaxpost

:

postbufferdiscard print_r

chmod 777 /tmp

temp

postContent-typeapplication/x-www-form-urlencoded1750

$_POSTpost_max_size8mmax_input_vars1000PHP

file_get_content("php://input")php://input

put$_POSTfile_get_content("php://input")

post16501750discard

put16501750file_get_contentsWarning

I haven"t completely cleared the reason why this happened. Guess so,

file_get_content ("php://input"), you can get data from all input streams without being affected by the php.ini instruction, but when you use this function to get content,
has two main points:
1.file_get_contents requires permission to write to temporary files
2. There is a set value for the obtained content size (specific number, or profile control, not understood). When the content size exceeds this value, the rest of the content will be written to a temporary file.

Why did this happen?

learn the difference between post and put, probably based on the semantic nature of the restful specification.

do not understand the reason for this =

Php
Jan.08,2022

guess that the input stream of PHP needs to have write access to temporary files.
is not only file_get_contents ('php://input'), but also GPC
when the transfer content size does not exceed a certain value (like 8k? ), there is no need to manipulate the temporary file, and when the temporary file expires,
needs permission to write to the temporary file, otherwise all data will be lost.

The difference between the results of

post and put requests may be due to:
when there is no temporary file write permission

post:PHP" POST data can't be buffered; all data discarded" file_get_contents('php://input')$_POST
put:discard all datafile_get_contents('php://input')strlen(file_get_contents('php://input'))8192
Menu