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 =