2013-01-03 3 views
0

PHP FTP commands을 사용하여 CENTOS 6.3PHP 5.4.9을 실행 중입니다. 저는 한 도메인의 대용량 파일을 같은 서버의 FTP 계정으로 업로드하는 데이 방법을 사용하고 있습니다.동일한 도메인에서 업로드 속도가 느림

작은 파일도 업로드하는 데 시간이 오래 걸립니다. 약 10-15 초입니다. 그들은 결국 업로드합니다. 같은 스크립트를 사용하여 다른 서버에 업로드하면 초당 업로드 속도가 빨라집니다.

동일한 FTP 자격 증명을 다른 서버에서 사용할 수 있으며 빠르게 업로드됩니다. 같은 서버에있는 한 도메인의 FTP가 느린 이유는 무엇입니까?

는 스크립트를 사용하여 업데이트 : 그들은 동일한 서버에있는 경우

$ftp_server = "HOST NAME"; 
$ftp_user_name = "USERNAME"; 
$ftp_user_pass = "PASSWORD"; 
$ftp_folder = "/FTP DIRECTORY"; 
$path = "/testing/"; 
$file_name = $_FILES["theFile"]["name"]; 
$source_file = $_FILES["theFile"]["tmp_name"]; 
$destination_file = $ftp_folder.$path.$file_name; 
$destination_path = $ftp_folder.$path; 


function uploadFTP($ftp_server, $ftp_user_name, $ftp_user_pass, $source_file, $destination_file, $destination_path) { 
    $conn_id = @ftp_connect($ftp_server); // set up basic connection 
    $login_result = @ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); // login with username and password 
    if ((!$conn_id) || (!$login_result)) { // check connection 
     return false; 
    } else { 
     $check = @ftp_chdir($conn_id, $destination_path); //check to see if folder is there 
     if ($check) { 
      $upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY); // upload the file 
      if (!$upload) { // check upload status 
       return false; 
      } else { 
       return true; 
      } 
     } else { 
      $check = @ftp_mkdir($conn_id, $destination_path); //make new folder 
      if ($check) { 
       $upload = @ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY); // upload the file 
       if (!$upload) { // check upload status 
        return false; 
       } else { 
        return true; 
       } 
      } else { 
       return false; 
      } 
     } 

    } 
    @ftp_close($conn_id); //close ftp 
} 
+0

ftp 주소에 따라 트래픽이 라우터 외부로 나가 네트워크로 되돌아 가야 할 수도 있습니다. 터미널에서'tracert '를 시도하십시오. –

답변

1

, 왜 그냥 대신에 그들을 다시 복용 후, 그들을 밖으로 보내는 통해 파일을 복사하지? 아웃 바운드 및 인바운드 연결로 포트 21 (FTP)을 막히고 있다고 생각합니다.

:: 편집 : 나는 이것을 알고

는 코드 검토 아니지만, 여기에 약간의 개선의 소수의 개정이다 :

$ftp_server = "HOST_NAME"; 
$ftp_user_name = "USERNAME"; 
$ftp_user_pass = "PASSWORD"; 
$ftp_folder = "/FTP_DIRECTORY"; 
$path = "/testing/"; 
$file_name = $_FILES["theFile"]["name"]; 
$source_file = $_FILES["theFile"]["tmp_name"]; 

/** 
* OLD CODE: 
* $destination_file = $ftp_folder . $path . $file_name; 
* $destination_path = $ftp_folder . $path; 
* 
* NEW CODE: 
* $destination_path = $ftp_folder . $path; 
* $destination_file = $destination_path . $file_name; 
* 
* REASON FOR CHANGE: Saves you 1 concat, also, 1 less use of ftp_folder and path 
*/ 
$destination_path = $ftp_folder . $path; 
$destination_file = $destination_path . $file_name; 


function uploadFTP($ftp_server, $ftp_user_name, $ftp_user_pass, $source_file, $destination_file, $destination_path) { 
    /** 
    * OLD CODE: 
    * $conn_id = @ftp_connect($ftp_server); # set up basic connection 
    * 
    * REASON FOR CHANGE: There are times to suppress errors, this is not one of them. 
    */ 
    $conn_id = ftp_connect($ftp_server) or die('Couldn\'t connect to ' . $ftp_server); # set up basic connection 

    /** 
    * REASON FOR NO CHANGE: ftp_login throws a warning on failure. 
    */ 
    $login_result = @ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); # login with username and password 

    if (empty($conn_id) || empty($login_result)) { # check connection 
     return false; 
    } else { 
     /** 
     * OLD CODE: 
     * $check = @ftp_chdir($conn_id, $destination_path) 
     * 
     * REASON FOR CHANGE: $check is redundant 
     */ 
     if (@ftp_chdir($conn_id, $destination_path)) { # check to see if folder is there 
      /** 
      * OLD CODE: 
      * $upload = @ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY); 
      * 
      * REASON FOR CHANGE: $upload is redundant 
      */ 
      if (ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY)) { # upload the file & check upload status 
       return true; 
      } else { 
       return false; 
      } 
     } else { 
      /** 
      * OLD CODE: 
      * $check = @ftp_mkdir($conn_id, $destination_path); 
      * 
      * REASON FOR CHANGE: $check is redundant 
      */ 
      if (@ftp_mkdir($conn_id, $destination_path)) { # make new folder 
       /** 
       * OLD CODE: 
       * $upload = @ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY); 
       * 
       * REASON FOR CHANGE: $upload is redundant 
       */ 
       if (@ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY)) { # upload the file & check upload status 
        return true; 
       } else { 
        return false; 
       } 
      } else { 
       return false; 
      } 
     } 

    } 
    ftp_close($conn_id); # close ftp 
} 

버전 2 :

$ftp_server = "HOST_NAME"; 
$ftp_user_name = "USERNAME"; 
$ftp_user_pass = "PASSWORD"; 
$ftp_folder = "/FTP_DIRECTORY"; 
$path = "/testing/"; 
$file_name = $_FILES["theFile"]["name"]; 
$source_file = $_FILES["theFile"]["tmp_name"]; 
$destination_path = $ftp_folder . $path; 
$destination_file = $destination_path . $file_name; 


function uploadFTP($ftp_server, $ftp_user_name, $ftp_user_pass, $source_file, $destination_file, $destination_path) { 
    $conn_id = ftp_connect($ftp_server) or die('Couldn\'t connect to ' . $ftp_server); # set up basic connection 
    $login_result = @ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); # login with username and password 

    if (empty($conn_id) || empty($login_result)) { # check connection 
     return false; 
    } else { 
     if (@ftp_chdir($conn_id, $destination_path)) { # check to see if folder is there 
      /** 
      * OLD CODE: 
      * if (ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY)) { # upload the file & check upload status 
      * return true; 
      * } else { 
      * return false; 
      * } 
      * 
      * REASON FOR CHANGE: DRY (Don't Repeat Yourself). Abstracted code above to function. 
      */ 
      return uploadFTP_ftpPut($conn_id, $destination_file, $source_file); 
     } else { 
      if (@ftp_mkdir($conn_id, $destination_path)) { # make new folder 
       /** 
       * OLD CODE 
       * ... 
       * 
       * REASON FOR CHANGE: See above. 
       */ 
       return uploadFTP_ftpPut($conn_id, $destination_file, $source_file); 
      } else { 
       return false; 
      } 
     } 

    } 
    ftp_close($conn_id); # close ftp 
} 

function uploadFTP_ftpPut($conn_id, $destination_file, $source_file){ 
    # upload the file & check upload status 
    if (@ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY)) return true; 
    else return false; 
} 

의견이없는 버전 3 :

$ftp_server = "HOST_NAME"; 
$ftp_user_name = "USERNAME"; 
$ftp_user_pass = "PASSWORD"; 
$ftp_folder = "/FTP_DIRECTORY"; 
$path = "/testing/"; 
$file_name = $_FILES["theFile"]["name"]; 
$source_file = $_FILES["theFile"]["tmp_name"]; 
$destination_path = $ftp_folder . $path; 
$destination_file = $destination_path . $file_name; 


function uploadFTP($ftp_server, $ftp_user_name, $ftp_user_pass, $source_file, $destination_file, $destination_path) { 
    $conn_id = ftp_connect($ftp_server) or die('Couldn\'t connect to ' . $ftp_server); # set up basic connection 
    $login_result = @ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); # login with username and password 

    if (empty($conn_id) || empty($login_result)) return false; # check connection 

    if (@ftp_chdir($conn_id, $destination_path)) { # check to see if folder is there 
     return uploadFTP_ftpPut($conn_id, $destination_file, $source_file); 
    } else { 
     if (@ftp_mkdir($conn_id, $destination_path)) { # make new folder 
      return uploadFTP_ftpPut($conn_id, $destination_file, $source_file); 
     } else { 
      return false; 
     } 
    } 

    # BTW - you never get here :) 
    ftp_close($conn_id); # close ftp 
} 

function uploadFTP_ftpPut($conn_id, $destination_file, $source_file){ 
    # upload the file & check upload status 
    if (@ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY)) return true; 
    else return false; 
} 
+0

FTP 클라이언트를 사용하는 데 문제가있는 FTP 클라이언트 대신 웹 페이지를 사용하여 고객이이 도구를 사용하여 서버에 파일을 업로드합니다. 우리는 우리의 대역폭을 씹지 않도록 포트 21에 원합니다. –

+0

FTPing을 클라이언트로 시도 했습니까 (서버가 아닌 다른 시스템에서). 포트를 막히는 데 어떤 일이 일어날 지 명확하지 않지만 한 포트를 통해 상향식 및 하향식 데이터가 동시에 흐르는 경우이 포트를 통해 업로드하는 것보다 훨씬 느려질 것이라고 생각하십니까? 아니? – jsanc623

+0

문제없이 한 서버에서 다른 서버로 FTP를 보낼 수 있습니다. 계획대로 작동합니다. 우리는 두 대의 전용 서버를 가지고 있는데 하나에서 다른 서버로 갈 수 있지만 스크립트가 동일한 서버에 있으면 업로드는되지만 속도는 매우 느립니다. 내가 어딘가 우리 PHP 버전의 사용 권한 문제가 될 수 있지만 그 주석을 잠시 후에 찾을 수 없다는 것을 읽었습니다. –