2011-08-01 3 views
0

내 친구와 몇몇 친구들이 우리가 내부적으로 사용하는 우리의 파일 호스팅/공유 서비스를 설정하고 개인적으로 만들었습니다. 이것은 공용 서버가 아니며, 우리의 용도로만 설계된 서버는 아닙니다.8000 개 이상의 이미지에 대한 미리보기 이미지 생성

전체 내용은 다음 사양에서 호스팅됩니다.

  • 프로세서 : 8기가바이트의
  • OS : 윈도우 비스타 홈 프리미엄
  • HDD 비트 64 @ X2 1 TB SATA
  • 3.20 GHz의
  • RAM @ : AMD 페넘 II X4의 (955 모델)

파일 작업에 약간의 시간이 걸린다는 사실은 말할 것도없이 php.ini는 스크립트에 전용되어 실행 시간을 400 초로 늘리는 데 거의 1GB의 메모리 만 사용할 수 있도록 재 작성해야했습니다.

질문 :로드가 처리하기에 충분하지만 아래에 제공된 코드를 최적화하여 8000 개 이상의 이미지를 실행하고 시스템을 많이 지연시키지 않는 더 좋은 방법이 있습니까? 500 개 이상의 파일을 통과 한 후 중지하는 것은 말할 것도 없습니다.

그리고 실제 스크립트 코드는 다음과 같습니다.

function make_thumb($src,$dest,$desired_width) { 
    /* read the source image */ 
    $de_width = 100; 
    $source_image = imagecreatefromjpeg($src); 
    $width = imagesx($source_image); 
    $height = imagesy($source_image); 
    /* find the "desired height" of this thumbnail, relative to the desired width */ 
    $desired_height = floor($height*($desired_width/$width)); 
    /* create a new, "virtual" image */ 
    $virtual_image = imagecreatetruecolor($desired_width,$desired_height); 
    /* copy source image at a resized size */ 
    imagecopyresampled($virtual_image,$source_image,0,0,0,0,$desired_width,$desired_height,$width,$height); 
    /* create the physical thumbnail image to its destination */ 
    imagejpeg($virtual_image,$dest,75); 
} 

function get_files($images_dir,$exts = array('jpg','png','gif','jpeg')) { 
    $files = array(); 
    if($handle = opendir($images_dir)) { 
    while(false !== ($file = readdir($handle))) { 
     $extension = strtolower(get_file_extension($file)); 
     if($extension && in_array($extension,$exts)) { 
     $files[] = $file; 
     } 
    } 
    closedir($handle); 
    } 
    return $files; 
} 

/* function: returns a file's extension */ 
function get_file_extension($file_name) { 
    return substr(strrchr($file_name,'.'),1); 
} 

$images_dir = 'data/'.$key.'/photos/'; 
$thumbs_dir = 'data/'.$key.'/photos/f/'; 
$thumbs_width = 100; 
$images_per_row = 6; 

/** generate photo gallery **/ 
$image_files = get_files($images_dir); 
if(count($image_files)) { 
    $index = 0; 
    foreach($image_files as $index=>$file) { 
    $index++; 
    $thumbnail_image = $thumbs_dir.$file; 
    if(!file_exists($thumbnail_image)) { 
     $extension = get_file_extension($thumbnail_image); 
     if($extension) { 
     fm_thumb($images_dir.$file,$thumbnail_image,$thumbs_width); 
     } 
    } 
    echo '<a href="',$images_dir.$file,'" rel="gallery"><img src="',$thumbnail_image,'" class="photo-link"/></a>'; 
    if($index % $images_per_row == 0) { echo '<div class="clear"></div>'; } 
    } 
    echo '<div class="clear"></div>'; 
} 
else { 
    echo '<p>There are no images in this gallery.</p>'; 
} 
+1

무엇이 문제입니까? – pt2ph8

+0

질문에 대한 답변을 –

+2

로 보내주세요. ImageMagick을 설치하고 PHP를 통해 명령 줄에서 호출하려고합니다. – Blender

답변

0

당신은 사용할 수 있습니다 당신이 당신의 서버에 설치하거나 컴파일 된 언어를 쓸 수 ImageProcessor, 그것은 PHP를보다 빠르게 될 것입니다, 당신은 당신이 사용하는 응용 프로그램에 따라 리소스 사용을 제한 할 수 있습니다.

shell_exec('console command here')을 사용하면이 작업을 수행 할 수 있습니다.

http://php.net/manual/en/function.shell-exec.php

관련 문제