Reputation: 877
In PHP Curl code, we can send 16,000 characters only at once. If at all the data sent contains more than 16,000 characters, then the data is broken down and sent to server.
Here is how the data is broken down:
How the data is passed:
$parameters {
"Data1" => 1.
"Data2" => <string_containing_20000_characters>,
"Data3" => <string_containing_25000_characters>,
"Data4" => 4
}
How it is sent to the server:
_POST {
"Data1" => 1.
"Data2" => <first_16000_characters><first_4000_characters>,
"Data3" => <first_16000_characters><first_9000_characters>,
"Data4" => 4
}
My PHP Code :
$curl_post_data = array("Data1" => "1", "Data2" => "<string_containing_20000_characters>", "Data3" => "<string_containing_25000_characters>", "Data4" => "4");
$curl = curl_init($rest_webservice_url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$rest_return_data = curl_exec($curl);
curl_close($curl);
echo $rest_return_data;
In php.ini below changes has been done.
max_execution_time = 300
max_input_time = 600
memory_limit = 1280M
post_max_size = 2048M
upload_max_filesize = 2048M
max_file_uploads = 200
Could please anyone can help me out what is the wrong with my above code.
Upvotes: 0
Views: 1813
Reputation: 15827
You have to edit your web sever configuration file too (on the server that receives the data).
If your're using nginx set client_max_body_size 10M
or any other value you think is appropriate.
On apache you would have LimitRequestBody 10485760
(10MB)
It is advisable to set reasonable values, ex. not 2GB
Upvotes: 1
Reputation:
Give this a try:
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0)
Seems that CURL will set an extra header when sending large data: Expect: 100-Continue
, which in your case you do not want. Mozilla Developer network describes it as:
The Expect HTTP request header indicates expectations that need to be fulfilled by the server in order to properly handle the request.
The only expectation defined in the specification is Expect: 100-continue, to which the server shall respond with:
100 if the information contained in the header is sufficient to cause an immediate success, 417 (Expectation Failed) if it cannot meet the expectation; or any other > 4xx status otherwise. For example, the server may reject a request if its Content-Length is too large.
No common browsers send the Expect header, but some other clients such as cURL do so by default.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expect
The RFC states: (https://www.rfc-editor.org/rfc/rfc7231#section-5.1.1)
A server that receives a 100-continue expectation in an HTTP/1.0 request MUST ignore that expectation.
Upvotes: 2