2013-02-24 2 views
1

나는 어떤 해결책도 얻지 못 했으므로 어쩌면 누군가가 나를 가리킬 수 있습니다. 왜이 스크립트가 NGINX + php5.3.21에서 작동하지 않고 아파치 + php5.2.17에서 잘 작동하는지, 아마도 PHP의 무언가 .ini 아니면 그냥 nginx.conf에서 뭔가를 놓치고 있습니까?왜이 PHP 스크립트가 NGINX가 아닌 아파치에서 작동합니까?

헤더가 파일을 다운로드하고 취소되거나 완료된 경우 추적하여 강제로 수행해야합니다.

그냥 nginx에서 다운로드를 시작하게하려면 마지막으로 flush()를 주석 처리해야합니다. 하지만 여전히 취소 또는 완료되면 파일 "진행"을 추적하지 않습니다. 아파치는 괜찮습니다! ((감사

<?php 
$FOLDER_PROGRESS = 'progress/'; 
$FOLDER_FILES = 'files/'; 

switch($_REQUEST['acc']){ 

case 'download': 

    $file = trim($_REQUEST['n']); 

    if(!file_exists($FOLDER_FILES.$file)){ 
     echo '<script>alert("Error: The file do not exists.");</script>'; 
    } else { 
     $continue = 'OK'; 
    } 

    if($continue=='OK'){ 

     $result = fopen($FOLDER_FILES.$file,'r'); 
     $bytes = filesize($FOLDER_FILES.$file); 

     if($bytes<1){ 
      //header('Location: /'); 
      echo '<script>alert("Error: The file bytes length is 0.");</script>'; 
     } else { 

      $fp1 = fopen($FOLDER_PROGRESS.trim($_REQUEST['tmp']).'.html','w'); 
      fwrite($fp1,'Downloading'); 
      fclose($fp1); 

      header("Pragma: public"); 
      header("Expires: 0"); 
      header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
      header("Cache-Control: public"); 
      header("Content-Description: File Transfer"); 
      header("Content-type: application/force-download"); 
      header("Content-Disposition: attachment; filename=".$file); 
      header("Content-Type: application/octet-stream"); 
      header("Content-Transfer-Encoding: binary"); 
      header("Content-Length: ".$bytes.""); 

      ignore_user_abort(true); 

      while (!feof($result)) { 
       echo fread($result, 4096); //handle 
       if (connection_status()!=0 || connection_aborted()){ 
        $bytes_transferred = ftell($result); //handle 
        if($bytes_transferred<$bytes) $accion = 'Canceled'; else $accion = 'Done!'; //Done here not run. 
        file_put_contents($FOLDER_PROGRESS.trim($_REQUEST['tmp']).'.html',$accion); 

        sleep(2); 
        file_put_contents($FOLDER_PROGRESS.trim($_REQUEST['tmp']).'.html','Waiting'); 
        flush(); 
       die; 
       } else { 
        $cuenta = ftell($result)/$bytes * 100; 
        if($cuenta>=100){ 
         $cuenta = 'Done!'; 

        } else { 
         $cuenta = 'Downloaded '.round($cuenta).'%'; 
        } 
        file_put_contents($FOLDER_PROGRESS.trim($_REQUEST['tmp']).'.html',$cuenta); 
        if($cuenta=='Done!'){ 
         sleep(2); 
         file_put_contents($FOLDER_PROGRESS.trim($_REQUEST['tmp']).'.html','Waiting'); 
         flush(); 
        } 
       } 
       //Activate this for delay download. 
       //flush(); 
       //sleep(1); 
      } 
      fclose($result); 

     } 

    } 

break; 

case 'tmp':   

    //create file control 

    //$temp = '__'.time(); 
    $temp = '__'.$_REQUEST['nf']; 
    $fp = fopen($FOLDER_PROGRESS.$temp.'.html','w'); 
    fwrite($fp,'Waiting'); 
    fclose($fp);        

    echo trim($temp); 

break;       

} 
?> 

PHP가 잘 작동은 phpinfo() 모든 긍정적 인 정보를 반환

nginx.conf
user www-data; 
worker_processes 8; 
pid /var/run/nginx.pid; 

events { 
    worker_connections 1024; 
    # multi_accept on; 
} 

http { 
    ## 
    # Basic Settings 
    ## 

    sendfile on; 
    tcp_nopush on; 
    tcp_nodelay on; 
    keepalive_timeout 0; 
    client_max_body_size 2048m; 
    types_hash_max_size 2048; 
    server_tokens off; 

    # 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"; 

    # gzip_vary on; 
    # gzip_proxied any; 
    # gzip_comp_level 6; 
    # gzip_buffers 16 8k; 
    # gzip_http_version 1.1; 
    # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; 

    ## 
    # nginx-naxsi config 
    ## 
    # Uncomment it if you installed nginx-naxsi 
    ## 

    #include /etc/nginx/naxsi_core.rules; 

    ## 
    # nginx-passenger config 
    ## 
    # Uncomment it if you installed nginx-passenger 
    ## 

    #passenger_root /usr; 
    #passenger_ruby /usr/bin/ruby; 

    ## 
    # Virtual Host Configs 
    ## 

    include /etc/nginx/conf.d/*.conf; 
    include /etc/nginx/sites-enabled/*; 
} 


#mail { 
#  # See sample authentication script at: 
#  # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript 
# 
#  # auth_http localhost/auth.php; 
#  # pop3_capabilities "TOP" "USER"; 
#  # imap_capabilities "IMAP4rev1" "UIDPLUS"; 
# 
#  server { 
#    listen  localhost:110; 
#    protocol pop3; 
#    proxy  on; 
#  } 

및 mysite.conf

server { 
      listen 80; 
      server_name mysite.com www.mysite.com; 

      access_log /var/log/nginx/mysite.access_log; 
      error_log /var/log/nginx/mysite.error_log; 

      root /var/www/www.mysite.com; 
      index index.php index.htm index.html; 

      location ~ \.php$ { 
       fastcgi_pass 127.0.0.1:9000; 
       fastcgi_index index.php; 
       fastcgi_param SCRIPT_FILENAME /var/www/www.mysite.com$fastcgi_script_name; 
       include fastcgi_params; 
      } 

    }   
+0

당신이 PHP를 전혀) (' sjdaws

+0

메시지 편집, 거기에 nginx 설정 :] –

답변

1

. 해결했습니다! 모든 것이 fastcgi 설정대로였습니다! FastCGI는 처리가 끝날 때까지 버퍼를 클라이언트에 출력하지 않으므로 flush '알 수 없음'입니다. ? 같은 문제를 가진 다른 사람을 위해 는 :; 내부`당신은

fastcgi_keep_conn on; 
fastcgi_read_timeout 600; 
fastcgi_buffer_size 1k; 
fastcgi_buffers 128 1k; 
fastcgi_max_temp_file_size 0; 
gzip off; 
관련 문제