nginx 1.0.5 + php-cgi (PHP 5.3.6)가 실행 중입니다. ~ 1GB 파일을 업로드해야합니다 (1 ~ 5 개의 병렬 업로드가 필요합니다). 아약스 업로드를 통해 큰 파일을 업로드하려고합니다. 모든 것이 작동하지만 PHP는 업로드 할 때마다 많은 메모리를 사용합니다. memory_limit = 200M으로 설정했는데 최대 150MB 크기의 파일을 업로드 할 수 있습니다. 파일이 더 크면 업로드가 실패합니다. memory_limit를 더 크게 설정할 수는 있지만, PHP가 모든 메모리를 먹을 수 있기 때문에 잘못된 방법이라고 생각합니다.PHP 입력에 의한 업로드 처리 중 PHP의 메모리 사용량 감소
$input = fopen('php://input', 'rb');
$file = fopen('/tmp/' . $_GET['file'] . microtime(), 'wb');
while (!feof($input)) {
fwrite($file, fread($input, 102400));
}
fclose($input);
fclose($file);
/etc/nginx/nginx.conf :
user www-data;
worker_processes 100;
pid /var/run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
client_max_body_size 2g;
# server_tokens off;
server_names_hash_max_size 2048;
server_names_hash_bucket_size 128;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
을/etc/nginx를/사이트 사용/SRV 나는 서버 측 업로드를 처리하기 위해 (이 단순화 것)이 PHP 코드를 사용 .conf :
server {
listen 80;
server_name srv.project.loc;
# Define root
set $fs_webroot "/home/andser/public_html/project/srv";
root $fs_webroot;
index index.php;
# robots.txt
location = /robots.txt {
alias $fs_webroot/deny.robots.txt;
}
# Domain root
location/{
if ($request_method = OPTIONS) {
add_header Access-Control-Allow-Origin "http://project.loc";
add_header Access-Control-Allow-Methods "GET, OPTIONS, POST";
add_header Access-Control-Allow-Headers "Authorization,X-Requested-With,X-File-Name,Content-Type";
#add_header Access-Control-Allow-Headers "*";
add_header Access-Control-Allow-Credentials "true";
add_header Access-Control-Max-Age "10000";
add_header Content-Length 0;
add_header Content-Type text/plain;
return 200;
}
try_files $uri $uri/ /index.php?$query_string;
}
#error_page 404 /404.htm
location ~ index.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $fs_webroot/$fastcgi_script_name;
include fastcgi_params;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param PATH_INFO $fastcgi_script_name;
add_header Pragma no-cache;
add_header Cache-Control no-cache,must-revalidate;
add_header Access-Control-Allow-Origin *;
#add_header Access-Control-Allow-Headers "Content-Type, X-Requested-With, X-File-Name";
}
}
PHP로 메모리 사용을 줄이는 방법을 아는 사람은 누구입니까? 감사합니다. .
나는 당신의 스크립트가 실제로 무엇을하는지 이해하지 못한다. 단지'copy'를 사용해 보았습니까? 왜 파일을 ftp하는 것과는 대조적으로 php를 사용해야합니까? –
> 스크립트가 실제로하는 일을 이해할 수 없습니다. 업로드 한 파일을 저장하는 중입니다. > 사본을 사용해 보셨습니까? 그리고 어떻게 도움이 될까요? > 왜 파일을 ftp하는 대신 PHP를 사용해야합니까? 웹 업로드가 필요합니다. 나는 FTP가 필요 없다. – andser
어쩌면 PHP를 완전히 건너 뛰고 Nginx 업로드 모듈을 사용할 수 있습니까? (http://www.grid.net.ru/nginx/upload.en.html) – mobius