apache2 + php5 환경에서 큰 파일 업로드하기 edit

Apache2 + PHP5 환경에서 큰파일을 업로드할때 들어온 POST 데이터들을 모두 메모리에 넣은 뒤 tmp에 저장시킨다음 지정된 디렉토리로 이동하는줄 알고 큰파일을 업로드 시킬경우 메모리가 터져나가 안되는줄 알고있었는데, 다시해보니 잘못알고 있었다.

php.iniupload_max_filesizepost_max_size를 각각 2G씩 설정했을땐 아예 모든크기의 파일이 업로드되지 않았다.(큰 파일은 끝에서 멈춰버렸고 작은파일은 아예 진행이 안됨) 이유는 모르겠으나 추측하건데 POST 최대 크기값이 각 파일들의 크기값과 같거나 작아서(post_max_size <= upload_max_filesize) 그랬거나 단순히 2GG심볼을 이해하지 못해서 그랬을지도 모른다.(php 공식사이트엔 이해한다고 되어있다.)
http://php.net/manual/en/ini.core.php

PHP allows shortcuts for bit values, including K (kilo), M (mega) and G (giga). PHP will do the conversions automatically if you use any of these. Be careful not to exceed the 32 bit signed integer limit (if you're using 32bit versions) as it will cause your script to fail.

Myth of 'memory_size'


이건 거의 미신수준이다.(하지만 구버전에선 어떤지 모르겠다.)

http://stackoverflow.com/questions/2854283/writing-direct-to-disk-with-php

I don't believe the myth that 'memory_size' should be the size of the uploaded file. The files are definitely not kept in memory... instead uploaded chunks of 1MB each are stored under /var/tmp and later on rebuild under /tmp before moving to the web/user space.

I'm running a linux-box with only 64MB RAM, setting the memory_limit to 16MB and uploading files of sizes about 100MB is no problem at all! (http://php.net/manual/en/features.file-upload.php)

PHP settings that related to file upload


php.ini:
; Whether to allow HTTP file uploads.
file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
upload_tmp_dir = /home/tmp

; Maximum allowed size for uploaded files.
upload_max_filesize = 2000000000  ; about 1.86G

; Maximum size of POST data that PHP will accept.
post_max_size = 2147483648  ; 2G

max_execution_time = 30     ; Maximum execution time of each script, in seconds
max_input_time = 60 ; Maximum amount of time each script may spend parsing request data

upload_tmp_dir


시스템 환경에 맞게 설정.

upload_max_filesize and post_max_size


업로드되는 각 파일의 최대 크기이며 post_max_size는 HTTP POST Request의 최대 크기이므로 post_max_size사이즈를 좀더 크게 설정.('multipart/form-data' is also POST Request)

max_execution_time and max_input_time


테스트해보진 않았지만 업로드할 파일의 크기가 매우 큰경우 timeout되어 업로드가 안될경우 늘려주면 될듯.

http://www.radinks.com/upload/config.php

These settings define the maximum life time of the script and the time that the script should spend in accepting input. If several mega bytes of data are being transfered max_input_time should be reasonably high.

Apache2(the webserver) LimitRequestBody option


Apache2 웹서버의 LimitRequestBody의 기본값은 0(무제한)이기때문에 따로 설정되어있지 않다면 만질필요가 없다.

http://www.radinks.com/upload/config.php

The apache webserver has a LimitRequestBody configuration directive that restricts the size of all POST data regardless of the web scripting language in use. Some RPM installations sets limit request body to 512Kb. You will need to change this to a larger value or remove the entry altogether.

Client side script Uploadify


http://www.uploadify.com/demos/

참고



구글링중 발견한 'Apache Commons Java 라이브러리/컴포넌트'는 Apache2 웹서버와 관계가 없다.


http://serverfault.com/questions/109557/best-practice-apache-file-upload

I think you're confusing Apache httpd (Web Server) with other Apache Group projects. Apache Group hosts the "Commons" project which a large collection of Java libraries for use in your own Java applications.

apache2 httpd 컴파일 옵션 지정


http://blog.naver.com/PostView.nhn?blogId=woodair&logNo=100090608241&parentCategoryNo=38&viewDate=¤tPage=1&listtype=0

raw 영상 , DVD 이미지 파일등 그 크기가 2기가 이상을 상회하는 파일들이 넘쳐나고 있는데 이와같은 파일을 웹을 통해 전송하기 위한 리눅스 컴파일 환경설정에 대한 내용입니다.

1. 커널 2.4 이상이어야 하며,
2. Apache2, PHP5 컴파일시 아래와 같은 컴파일 플레그를 지정함으로 2기가 이상의 대용량 처리 환경을 만들수가 있습니다.

shell] # CFLAGS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
shell] # export CFLAGS
shell] # cd httpd-2.x.x
shell] # ./configure \
--prefix=/usr/local/apache2 \
--enable-mods-shared=all \
--enable-so
....
.... 
Newer -> <- Older