Uploading large file (45MB) via AJAX failing - php

I'm trying to upload files via AJAX. Small files ~10MB are being uploaded successfully.
However, when I try to upload larger files, it fails with the following message:
Internal Server Error
The server encountered an internal error or misconfiguration and was
unable to complete your request.
Please contact the server administrator, webmaster#.com and inform
them of the time the error occurred, and anything you might have done
that may have caused the error.
More information about this error may be available in the server error
log.
Additionally, a 500 Internal Server Error error was encountered while
trying to use an ErrorDocument to handle the request.
I'm using Laravel 5 on dreamhost.
I've put debugging messages everywhere, but it seems that my PHP code is not being executed at all. Also, there's no info in error.log either.
I've checked php.ini with following settings:
max_execution_time 30
max_file_uploads 20
post_max_size 500M
upload_max_filesize 500M
Intially, I had mounted /tmp folder at one place which had partition size of 100MB. At that time, the error.log said "modsecurity: input filter failed writing 8192 bytes to temporary file"
So I changed to location of /tmp folder to my home folder in order to remove size restrictions, but not working.
Here is the current behaviour:
File upload shows 100%.
Then the request waits for sometime without causing logs.
After a while, the above mentioned error message is returned.
Let me know which further info is required.
Thank you very much!

For such issues, You should play with few parameters of php.ini.
max_execution_time
max_input_time
post_max_size
upload_max_filesize
Try to keep max_execution_time and max_input_time to ZERO (0).
It won't bound your execution to 30 seconds.
Hope this helps!!

Related

Reasons of 500 internal server error in php

I am trying to upload the large image(1 MB) files on server using php code but it is
showing the 500 internal server error it is only uploading up to 128 KB.
Even though i have checked all the required setting of my server
all settings are correct i am not getting how to trace this error.Is
there any other setting which i don't know so please help me to find out or
if all settings is fine then please help me trace out this 500 internal server error.
Settings which i have already verified.
memory_limit 90M
post_max_size 64M
upload_max_filesize 64M
FcgidMaxRequestLen 104857600
Below is the error:
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster#domain.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
Use two lines at the top of the page to display errors
ini_set("display_errors", "1");
error_reporting(E_ALL);

Very long PHP operation: 500 Internal Server Error

I am reading 10,000 csv files each has 1000 rows and remove the duplicate and create new file
For that
I read line by line and store the data in a array.
When I store new data in the array, I check the weather it is not duplicate (weather the array already have the data)
Then recreate csv using array
Additionally I changed following in the php.ini
max_execution_time = 30000
max_input_time = 60000
memory_limit = -1
error_log = error_log
But I am getting following error. There is no error log. Is there any other configuration to change in the php.ini. Please help me on it
Internal Server Error
The server encountered an internal error or misconfiguration and was
unable to complete your request.
Please contact the server administrator, webmaster#xxxxxx.com and
inform them of the time the error occurred, and anything you might
have done that may have caused the error.
More information about this error may be available in the server error
log.
Additionally, a 404 Not Found error was encountered while trying to
use an ErrorDocument to handle the request.
Apart from checking for the Apache Timeout, you should try to break this script once & try to run it in batches of probably 2000 csv files.
It is also possible that some data in one of the CSV files is causing this error, which would be identified if you break it in batches of 2000 files & run.

Laravel Memory: 'out of memory (allocated 262144)'

I'm a system administrator which handles a server that hosts an internal api created using Laravel 5. The data source is a SQL Server hosted on another server and the api is used in a IOS app for mobile phones. When the developers created the api, this error was not present and no other memory errors were found. When we went live this error has been popping up from time to time.
[2015-06-01 23:01:52] production.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Out of memory (allocated 262144) (tried to allocate 140189808036120 bytes)' in Unknown:0
I checked RAM, CPU, swap etc etc of the server but everything was ok. Not much of the resources are being consumed. I've checked PHP Memory limit from php.ini and is set to -1 which is the max according to PHP. I've checked it on CLI, phpinfo.php and httpd.conf I don't see anything wrong. The team tried following this link Allowed memory size of X bytes exhausted
This is a problem in the ios app because the app searches for a correct return code but when this error comes out, even if the ios app transaction is correct, it returns an error because the return code is incorrect as it is returning the code for the memory error.
The first thing I could think of was to restart the Apache httpd service. This immediately solved the issue. but I knew this is not a permanent fix for the issue. When I researched further, I got to know that the error comes when certain PHP scripts require more memory than PHP was allowed by default.
So the solution is to increase the memory allocated for PHP. How to do that? There are 4 possible ways –
Try looking for the php.ini file. You might find some redundant php.ini files, so make sure you have got the one which is actually being read by PHP. o be sure, create a new php file in your root folder, say “check.php” and have phpInfo(); within the php open and close tags. Execute this file to get the information on where the php.ini is residing. Normally it will be in /usr/local/lib/php.ini
Open the php.ini file in a text editor like TextPad (not in Notepad) and change the values for memory_limit. By default you should see memory_limit = 8M. Try changing it to 12M. If it doesn’t work, increase it to 16M or even 24M and so on.
In case you can’t find the php.ini file or do not have access to it, then open up the file which was throwing the error (admin.php in my case) and add a line below just after ini_set(’memory_limit’, ‘12M’);
You can even consider adding a line in .htaccess file which will resolve the issue.
php_value memory_limit 32M
Or else, Try adding this line to your php file:
Increasing memory allocated to PHP
ini_set(“memory_limit”,”16M“);

PHP script dies before ftp_get() finishes downloading a file

I know how to download a file from a server using FTP with PHP.
I have a list of files to download from the ftp to an internal storage.
I use ftp_get() to download the list of files,
the first file size is: 126 mb, successfully downloaded to my internal storage.
However the PHP function throws an error 500, and then dies without continuing.
The error I get:
Internal Server Error
The server encountered an internal error or misconfiguration and was
unable to complete your request.
Please contact the server administrator, webmaster#zzz.com and inform
them of the time the error occurred, and anything you might have done
that may have caused the error.
More information about this error may be available in the server error
log.
Additionally, a 404 Not Found error was encountered while trying to
use an ErrorDocument to handle the request.
Any idea what I should do in order for the function to complete its run successfully?
You need to increase the timeout then. 180 is in seconds, which is 3 minutes. Try setting it to 600. I.e.: FTP_TIMEOUT_SEC, 600 or higher, depending on how much more time is needed. You probably could even try FTP_TIMEOUT_SEC, 0 which I think is NO time limit.
It is already commented for one more question similar to this. Please try this. It should work.
Maybe you exceeded the maximum execution time.
Try to increase it:
https://www.php.net/manual/en/function.set-time-limit.php

500 Internal Server Error coming when large amount of data is POST to a php file around more than 1 mb

Can anyone explain me why 500 Internal Server Error coming when large amount of data is POST to a php file and the data is around more than 1 mb?
My best guess is that the file is exceeding your configured maximum file size. See http://php.net/manual/en/features.file-upload.php for various discussion and solutions for throwing a prettier error message.
As to increasing those limits, look at "post_max_size" and "upload_max_size" in your .ini file. You'll also likely need to extend the execution time of the script, via "max_input_time" and "max_execution_time".
You can set these in your .ini, or in code as well. See http://blogs.sitepoint.com/upload-large-files-in-php/ for more info.

Categories