그룹 최신글인데 속도가 느리네요 ㅜㅜ
본문
제가 sql 쪽도 모르고 php쪽도 많이 부족해서 이렇게 도움 요청드립니다.
속도 향상을 어떻게 해야할지 몰라서 이렇게 올립니다. ㅠㅠ
이 것은 그룹 최신글을 이용해서 메인 페이지에 사진과 제목으로 최신글을 보여주는 것입니다.
http://www.hojumoney.com.au/index_test.php
위 주소로 가시면 테스트 화면을 보실 수 있습니다.
lib 파일
<?
if (!defined('_GNUBOARD_')) exit;
// 함수 정의 시작
// 최신글 추출 - 선택한 그룹별로 원하는 게시판을 제외하고 원하는 수만큼 보여줌
function latest_group($skin_dir="", $gr_id, $rows=10, $subject_len=40, $no_table="", $category="", $orderby="")
{
global $config;
global $g4;
$list = array(); $limitrows = $rows;
$sqlgroup = " select bo_table, bo_subject from $g4[board_table] where gr_id = '$gr_id' ";
$sqlgroup .= " and bo_use_search=1 order by bo_order_search ";
$rsgroup = sql_query($sqlgroup);
if ($skin_dir)
$latest_skin_path = "$g4[path]/skin/$skin_dir";
else
$latest_skin_path = "$g4[path]/skin/$config[cf_latest_skin]";
for ($j=0, $k=0; $rowgroup=sql_fetch_array($rsgroup); $j++) {
$bo_table = $rowgroup[bo_table];
// 테이블 이름구함
$sql = " select * from {$g4[board_table]} where bo_table = '$bo_table'";
$board = sql_fetch($sql);
$tmp_write_table = $g4[write_prefix] . $bo_table; // 게시판 테이블 실제이름
// 옵션에 따라 정렬
$sql = "select * from $tmp_write_table where wr_is_comment = 0 ";
$sql .= (!$category) ? "" : " and ca_name = '$category' ";
$sql .= (!$orderby) ? " order by wr_id desc " : " order by $orderby desc, wr_id desc ";
$sql .= " limit $limitrows";
$result = sql_query($sql);
for ($i=0; $row = sql_fetch_array($result); $i++, $k++) {
if(!$orderby) $op_list[$k] = $row[wr_datetime];
else {
$op_list[$k] = is_string($row[$orderby]) ? sprintf("%-256s", $row[$orderby]) : sprintf("%016d", $row[$orderby]);
$op_list[$k] .= $row[wr_datetime];
}
$list[$k] = get_list($row, $board, $latest_skin_path, $subject_len);
$list[$k][bo_table] = $board[bo_table];
$list[$k][bo_subject] = $board[bo_subject];
$list[$k][bo_wr_subject] = cut_str($board[bo_subject] . $list[$k][wr_subject], $subject_len);
}
}
if($k>0) array_multisort($op_list, SORT_DESC, $list);
if($k>$rows) array_splice($list, $rows);
ob_start();
include "$latest_skin_path/latest.skin1.php";
$content = ob_get_contents();
ob_end_clean();
return $content;
}
/// 함수 정의 끝?>
스킨 파일
<?
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
$l=$i;
$l--;
?>
<div>
<?for ($i=0; $i<count($list); $i++) {
if($list[$i][file][0][view]){
$src = $list[$i][file][0][path]."/".$list[$i][file][0][file];
$img = $src;
}else{
// no 이미지를 비율적으로 만들어났음
$img = $latest_skin_path."/img/no_image.gif";
}
if($i==$l){
?>
<div class="row" id="main_news">
<div class="col-xs-12">
<div class="col-xs-12" id="latest_news_title">
<a href="<?=$list[$i]['href']?>">
<span>
<?=$list[$i]['subject']?>
</span>
</a>
</div>
<a href="<?=$list[$i]['href']?>">
<img src="<?=$img?>">
</a>
</div>
</div>
<?}?>
<?}?>
<? if (count($list) == 0) {?>
<td height="50" align="center" valign="middle">게시물이 없습니다.</td>
<?}?>
</div>
답변 3
이미지들이 문제인 것 같네요.
작게 보이는 이미지들이 실제로는 상당히 큰 사이즈들입니다.
링크된 페이지의 데이터 총량은 20.7메가 정도가 되는 군요.
실제 사이즈 이미지를 불러와서,
사이즈 크기만 지정하는 방식이 아닌,
썸네일로 불러오는 방식으로 바꿔야 할 듯 합니다.
크롬브라우져에서 F12누르시고 네트워크 탭 클릭후 새로고침해보시면 로딩이 느린부분을 확인하실수있어요 ~ 일단 이미지지들 썸네일화하는게 먼저같네요~
$thumb_width=120;//섬네일 최대폭(원하는대로 바꾸면 됩니다.)
$thumb_height=90;//섬네일 최대높이(원하는대로 바꾸면 됩니다.)
function thumbnail2($file, $save_filename, $max_width, $max_height)
{
$src_img = ImageCreateFromJPEG($file); //JPG파일로부터 이미지를 읽어옵니다
$img_info = getImageSize($file);//원본이미지의 정보를 얻어옵니다
$img_width = $img_info[0];
$img_height = $img_info[1];
if(($img_width/$max_width) == ($img_height/$max_height))
{//원본과 썸네일의 가로세로비율이 같은경우
$dst_width=$max_width;
$dst_height=$max_height;
}
elseif(($img_width/$max_width) < ($img_height/$max_height))
{//세로에 기준을 둔경우
$dst_width=$max_height*($img_width/$img_height);
$dst_height=$max_height;
}
else
{//가로에 기준을 둔경우
$dst_width=$max_width;
$dst_height=$max_width*($img_height/$img_width);
}
$dst_img = imagecreatetruecolor($dst_width, $dst_height); //타겟이미지를 생성합니다
ImageCopyResized($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $img_width, $img_height); //타겟이미지에 원하는 사이즈의 이미지를 저장합니다
ImageInterlace($dst_img);
ImageJPEG($dst_img, $save_filename); //실제로 이미지파일을 생성합니다
ImageDestroy($dst_img);
ImageDestroy($src_img);
}
$image = $list[$i][file][0][file]; //공백으로인한썸네일깨짐방지
// $image = urlencode($list[$i][file][0][file]); // 첫번째 파일이 이미지라면
if (preg_match("/\.(gif|jpg|png)$/i", $image)) {
$thumbdir = $g4[path]."/data/file/".$bo_table ;
$thumbsource="$g4[path]/data/file/$bo_table/" . $image;
$thumbimg = $thumbdir."/".$list[$i][wr_id].".thumb";
thumbnail2($tmpfile, $src, $tmpsize0, $tmpsize1);
@chmod($thumbimg, 0707);
}
$img = $thumbimg;
이 내용을 스킨 파일에
$src = $list[$i][file][0][path]."/".$list[$i][file][0][file];
$img = $src;
이부분을 주석 처리 하시고, 넣어 주면 될 듯 합니다. (테스트는 해보지 않았으니 오류가 있을수도...
)
!-->