fanfavorite Posted May 7, 2010 Share Posted May 7, 2010 Hey All, I have been struggling lately with execution times. I believe my host changed server settings, which they deny, but I keep getting 500 errors, which my host says is maximum execution time. Anyways, I have traced the script down and it seems that the main functions that take a long time are the copying ftp files. I have two functions, "copyDir" copies everything over to the server and "copyDir2" copies just the filenames with no data attached. Can someone please take a look and let me know if there is a faster way of doing these? function copyDir($conn_id,$path,$dst_dir){ $ar_files = @ftp_nlist($conn_id, $dst_dir); if (is_array($ar_files)){ for ($i=0;$i<sizeof($ar_files);$i++){ $st_file = basename($ar_files[$i]); if($st_file == '.' || $st_file == '..') continue; if (ftp_size($conn_id, $dst_dir.'/'.$st_file) == -1){ if (!is_dir($path.'/'.$st_file)) { @mkdir($path.'/'.$st_file); } if ($st_file != "layout" AND ($st_file != "templates" OR $_SESSION[ftp] != "anothertakestudios.com")) { copyDir($conn_id, $path.'/'.$st_file, $dst_dir.'/'.$st_file); } } else { @ftp_get($conn_id,$path.'/'.$st_file,$dst_dir.'/'.$st_file,FTP_BINARY); } } } } function copyDir2($conn_id,$path,$dst_dir){ $ar_files = @ftp_nlist($conn_id, $dst_dir); if (is_array($ar_files)){ for ($i=0;$i<sizeof($ar_files);$i++){ $st_file = basename($ar_files[$i]); if($st_file == '.' || $st_file == '..') continue; if (ftp_size($conn_id, $dst_dir.'/'.$st_file) == -1){ if (!is_dir($path.'/'.$st_file)) { @mkdir($path.'/'.$st_file); } copyDir2($conn_id, $path.'/'.$st_file, $dst_dir.'/'.$st_file); } else { $handle = @fopen($path.'/'.$st_file, "x"); fclose($handle); } } } } Thanks! Link to comment https://forums.phpfreaks.com/topic/201056-copy-ftp-directory/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.