HTTP Post file to webserver failure - php

From our offline application we want to post an xml file via HTTP Post to our webserver. This worked fine but when the xml is larger then 650KB the post failed.
The PHP settings on our webserver:
memory_limit 128M
post_max_size 32M
upload_max_filesize 16M
Somebody knows what the problem could be?
UPDATE
I've tested something on our webserver. I made a form with a textarea and paste the XML in the textarea. When I submitted the form I didnt get any results of the POST I echoed but when I paste the half of the XML I get the results.
Strange thing is I didnt got an error message when posting the whole XML.

Try putting this at the top of php file that you call on form submit:
set_time_limit(0);
Maybe your connection is too slow to send that file in allowed execution time of php script.

Run phpinfo() and check if these variables are what you think are. Maybe some .htaccess or other webserver configuration file is overwriting them. Also check if there's no connection timeout.
What response do you get from server when post fails?

Related

Failed POST request to Laravel containing files larger than 1MB

When sending files larger than 1MB in a POST request I get a (failed) response in Chrome. Files smaller than 1MB work fine so I expect that something is setting a limit of 1MB.
I am running phpinfo() to check the values in my php.ini file, which shows that upload_max_filesize=100M and post_max_size=100M. I have also checked the Laravel logs but there are no errors regarding this.
I am using Laravel 6.18.13 running on a Homestead box with PHP 7.4.5. My front-end application is using Angular 9. This is the code in Angular that sends the request:
const formData = new FormData();
params.files.forEach((file: File) => {
formData.append(`audio_files[]`, file, file.name);
});
return this.http.post<APIResponse>(url, formData);
Any ideas as to what might be setting this 1MB limit are appreciated.
Most web sites have multiple layers to consider:
web server / reverse proxy, e.g. nginx
php process
database
browser security
Nginx limits
For nginx make sure that the client_max_body_size directive is properly set. Must be set both in http and server context.
(would yield 413 entity too large http status code)
PHP limits
You are correct to adjust the following:
upload_max_filesize
post_max_size
file_uploads
max_file_uploads
Check also your PHP error and access log for more information.
Database limits
If the data is parsed to the a database, that could have some limits too. For MySQL consider the following:
max_allowed_packet
Browser
The browser or JavaScript could cancel the request, please check your console for warnings, make sure you are not sending incorrect headers, the request is cancelled by browser addins or similar.

PHP 7 post_max_size ini setting work for limiting raw POST data?

I am using Apache Thrift to move small base64 encoded files to a PHP backend (with Apache web server). It is essentially just an HTTP POST request with large amounts of raw body data. I want to limit how much data can be POSTed so that I don't even attempt to process files larger than my target (I will also have a small memory_limit). To test this I set in php.ini:
post_max_size=1K
I then confirmed that my setting was correctly picked up by running phpinfo().
However, when POSTing roughly 12K of raw textual data to my server I can still get the full contents using
file_get_contents("php://input");
My understanding is that PHP will simply strip out the data if post_max_size is exceeded instead of throwing an error or exception. Through searching how post_max_size works, information always seems to relate to file uploads rather than a raw post body. Is the post_max_size ini setting not actually looking at the raw size of post requests in addition to posted file upload data? Why when my post_max_size is exceeded do I still get everything that was posted? How can I prevent serving a request or handling large data if the POST raw body data size exceeds my limit? Any help is greatly appreciated.

FastCGI process exited unexpectedly when post data larger than 16 kB

I am uploading small images to a local IIS server running PHP. The images are sent by a POST HTTP request. Whenever the post size exceeds 16kB I get a 500 response from the server saying:C:\PhP\php-cgi.exe - The FastCGI process exited unexpectedly.
The problem persists even if I reduce the PHP script to:
<?php
?>
Also the problem did not occur when I ran the script on mongoose.
php_errors.log does not mention the problematic script.
I checked my php.ini file for post_max_size and memory_limit and what have you and found nothing to justify a PhP crash on 16kB of data.
I'm pretty new to IIS but I suspect the problem is there. I checked system.webServer/security/requestFiltering and found these values:
maxAllowedContentLength: 30000000
maxQueryString: 2048
maxURL: 4096
I have no idea what could be causing the problem or where to look next. Any help would be appreciated.
EDIT:
I found out that http.sys limits request content to 16 kB by default and changed that by adding a MaxRequestBytes field with 16MB value to registry HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HTTP\Parameters.
I was sure that was going to solve it, but it didn't.
It's an old thread, but I found a solution that worked for me: It seems that in case the POST request exceeds 16kb of size, PHP is writing a kind of a cache file to its local temp directory. So check your PHP.ini file (upload_tmp_dir) and make sure the local group IIS_IUSRS has write permission to this directory.

Ajax error - 0 after a long php script

I am using jquery ajax to send the url of a file (csv file) located on the server to my php script so as to process it.
The csv file contains telephone calls. If i have a file with even 10.000 calls everything is ok. But if i try a big file with like for example 20000 calls then i get an Ajax Error 0 . I check for server responce with firebug but i get none.
This behaviour occurs after like 40mins of w8ing for the php script to end. So why do i get this error on big files only? Does it have to do with apache, mysql or the server itself? Anyone able to help will be my personal hero cause this is driving me nuts.
I need a way to figure out whats happening exactly but firebug wont return a server responce. Any other way i can find out whats happening?
I checked the php error log and it reports nothing on the matter
Thanks in advance.
The script may have timed out:
See your php.ini file
max_execution_time
max_input_time ;# for the max time an input can be processed
Were your PHP.ini is depends on your enviroment, more information: http://php.net/manual/en/ini.php
Check:
max_input_time
This sets the maximum time in seconds a script is allowed to parse input data, like POST and GET. It is measured from the moment of receiving all data on the server to the start of script execution.
max_execution_time
This sets the maximum time in seconds a script is allowed to run before it is terminated by the parser. This helps prevent poorly written scripts from tying up the server. The default setting is 30. When running PHP from the command line the default setting is 0.
Also
Your web server can have other timeout configurations that may also interrupt PHP execution. Apache has a Timeout directive and IIS has a CGI timeout function. Both default to 300 seconds. See your web server documentation for specific details.
First enable php error by placing below code at top of the php file.
error_reporting(E_ALL);
Then as Shamil explained in this answer, checkout your max_execution_time settings of your php.
To check max_execution time, open your php.ini file and search for that, and then change it to a maximum value of say one hour (3600).
I hope this will fix your issue.
Thank you

Why is _POST sometimes empty when a textarea is posted in PHP

PHP 4.4 and PHP 5.2.3 under Apache 2.2.4 on ubuntu.
I am running Moodle 1.5.3 and have recently had a problem when updating a course. The $_POST variable is empty but only if a lot of text was entered into the textarea on the form. If only a short text is entered it works fine.
I have increased the post_max_size from 8M to 200M and increased the memory_limit to 256M but this has not helped.
I have doubled the LimitRequestFieldSize and LimitRequestLine to 16380 and set LimitRequestBody to 0 with no improvement.
I have googled for an answer but have been unable to find one.
HTTP Headers on firefox shows the content size of 3816 with the correct data, so its just not getting to $_POST.
The system was running fine until a few weeks ago. The only change was to /etc/hosts to correct a HELO issue with the exim4 email server.
I can replicate the issue on a development machine that has exim4 not running so I think it is just coincidence.
Thanks for your assistance.
I don't know enough to really provide a useful answer so the following is more a well-educated guess (at least I hope so).
First, you should debug the entire request, either by access_log or for example through firebug. (Good to have Firebug anyway.) To me your problem sounds like a redirect happens in between. I give you an example:
Assume this is your structure:
/form.php
/directory/index.php
This is your form:
<form action="/directory" method="post">
...
</form>
Problem in this case is, that even though /directory is a valid url, Apache will redirect you one more time to /directory/, thus you are loosing your payload (what is supposed to be in $_POST).
Could it be not the size related of the post, but how long the line is before a new line. If they use the Moodle WYSIWYG view the html would just get put into one line with no breaks. If you go into html and hit return around every 1000 characters does it work?
What is the enctype of the form? Could be that it limits the ammount of data send through the form.
You might also want to check the incoming raw $_POST data with:
file_get_contents('php://input');
To make sure their is actually data send.
Got these suggestions here.
It sounds like an Apache or Apache/PHP integration problem. If $_POST is empty it would hint that the http server is not giving the POST information to PHP. If I were you I'd investigate the Apache configuration.
This is obvious, but did you /etc/init.d/apache2 restart ?
Also, the error_log file should show some information about whether the post size exceeded the set limit. Consider increasing your verbosity for troubleshooting the issue

Categories