ob_start (버퍼링?)에 대한 질문입니다. 정보
ob_start (버퍼링?)에 대한 질문입니다.본문
제가 게시판에 자신의 댓글을 등록한 게시글을 최신순으로 뽑아내는걸 하려고 하는데
구현은 했습니다만 게시판의 양이 클 경우 속도가 느려집니다.
이 기능이 Head파일 먼저 뜨고, 게시판 시작하는 부분쯤에 위치해있는데
코딩 순서로 따지면 상당히 앞쪽에 위치해있는거죠.
근데 이 기능을 일단 버퍼에 저장시켜놓고(출력에서 제외시키고)
게시판 목록 다 뽑아내고, 밑에 foot파일 까지 다 완료시킨다음에
원래 위치에 출력을 시키고 싶습니다.
if(!$member['mb_id'])
echo "<font style='color:#9d9d9d; font-family: tahoma; font-size:8pt;'>§</font>";
else
{
echo "<div style='width:500px; height:20px; float: right; padding: 0 5 0 0;' align='right'>";
$sql2 = "select A.wr_subject, A.wr_id, A.wr_comment, trim(substring(A.wr_datetime,3,9)) ";
$sql2.= "from $write_table A inner join $write_table B on A.wr_num=B.wr_num and A.wr_id=B.wr_parent and A.wr_is_comment!=B.wr_is_comment ";
$sql2.= "where B.mb_id = '$member[mb_id]' ";
$sql2.= "group by A.wr_parent ";
$sql2.= "order by B.wr_id desc limit 0,20";
$result2 = sql_query($sql2);
$n_rows = mysql_num_rows($result2);
$n_fields = mysql_num_fields($result2);
echo "<table border='1' bordercolor='#000000' cellpadding='0' cellspacing='0' class='latest_comment'>";
echo "<tr height='15'>";
for($g=0; $g<$n_rows; $g++)
{
$n_title[] = mysql_result($result2, $g, 0);
$n_wr_id = mysql_result($result2, $g, 1);
$n_comment = mysql_result($result2, $g, 2);
$n_date = mysql_result($result2, $g, 3);
$s_len = 5; // 글자 제한수
$number = $g+1; // 게시물 번호
$n_table = substr($write_table,9);
$n_url = "./board.php?bo_table=$n_table&wr_id=".$n_wr_id;
$n_color = ($g + 70);
echo "<td width='20' style='cursor: pointer'><div style='background-color: #{$n_color}{$n_color}80' class='n_box' title='($n_date) $n_title[$g] [$n_comment]' onClick='location.href=\"$n_url\"' onMouseOver='this.style.backgroundColor=\"#a8a8a8\"' onMouseOut='this.style.backgroundColor=\"#{$n_color}{$n_color}80\"'>{$number}</div></td>";
}
echo "</tr>";
echo "</table>";
echo "</div>";
}
----------------------------------------------------------------
위 소스가 제가 구현하려는 기능입니다.
list.skin.php 파일에서 보면
<!-- 게시판 목록 시작 -->
<table width="<?=$width?>" align="center" cellpadding="0" cellspacing="0" class="bor-coll">
<tr height="25">
<td valign="bottom">
<!-- 분류 셀렉트 박스, 게시물 몇건, 관리자화면 링크 -->
<div class="board_top">
<div style="height:20px; float:left;">
<form name="fcategory" method="get" style="margin:0px;">
<? if ($is_category) { ?>
<select name=sca onchange="location='<?=$category_location?>'+this.value;" style="width:100px; height:20px">
<option value=''>전체</option>
<?=$category_option?>
</select>
<? } ?>
</form>
</div>
<div style="height:18px; float:right; padding: 1 2 0 0;">
<span style="color:#9d9d9d; font-family: tahoma; font-size:8pt;">Total <?=number_format($total_count)?></span>
<? if ($rss_href) { ?><a href='<?=$rss_href?>'><img src='<?=$board_skin_path?>/img/btn_rss.gif' border="0" align="absmiddle"></a><?}?>
<? if ($admin_href) { ?><a href="<?=$admin_href?>"><img src="<?=$board_skin_path?>/img/btn_admin.gif" title="관리자" align="absmiddle"></a><?}?>
</div>
이 부분 바로 다음에 시작합니다.
버퍼링 기능을 쓰지 않으면 위에 소스까지 브라우저가 출력하다가
제가 구현하려는 기능에 도착하면 db에서 뽑아내고 출력하는데
시간이 많이 걸리게 되는거죠. 이걸 무시하고 구현소스 바로 밑에부터
브라우저에 다~ 뿌리면 그때 저 구현기능 출력시키고 싶은겁니다.
ob_start(), ob_end_flush() 함수를 어느 위치에서
그리고 어떻게 써야 가능한지 궁금합니다.
이건 php.net에 가봐도 모르겠고, 다른 사람들이 올려놓은걸 봐도
설명이나 방법은 없고 그냥 어떻게 썻다 이런 얘기들뿐이라서요...
구현은 했습니다만 게시판의 양이 클 경우 속도가 느려집니다.
이 기능이 Head파일 먼저 뜨고, 게시판 시작하는 부분쯤에 위치해있는데
코딩 순서로 따지면 상당히 앞쪽에 위치해있는거죠.
근데 이 기능을 일단 버퍼에 저장시켜놓고(출력에서 제외시키고)
게시판 목록 다 뽑아내고, 밑에 foot파일 까지 다 완료시킨다음에
원래 위치에 출력을 시키고 싶습니다.
if(!$member['mb_id'])
echo "<font style='color:#9d9d9d; font-family: tahoma; font-size:8pt;'>§</font>";
else
{
echo "<div style='width:500px; height:20px; float: right; padding: 0 5 0 0;' align='right'>";
$sql2 = "select A.wr_subject, A.wr_id, A.wr_comment, trim(substring(A.wr_datetime,3,9)) ";
$sql2.= "from $write_table A inner join $write_table B on A.wr_num=B.wr_num and A.wr_id=B.wr_parent and A.wr_is_comment!=B.wr_is_comment ";
$sql2.= "where B.mb_id = '$member[mb_id]' ";
$sql2.= "group by A.wr_parent ";
$sql2.= "order by B.wr_id desc limit 0,20";
$result2 = sql_query($sql2);
$n_rows = mysql_num_rows($result2);
$n_fields = mysql_num_fields($result2);
echo "<table border='1' bordercolor='#000000' cellpadding='0' cellspacing='0' class='latest_comment'>";
echo "<tr height='15'>";
for($g=0; $g<$n_rows; $g++)
{
$n_title[] = mysql_result($result2, $g, 0);
$n_wr_id = mysql_result($result2, $g, 1);
$n_comment = mysql_result($result2, $g, 2);
$n_date = mysql_result($result2, $g, 3);
$s_len = 5; // 글자 제한수
$number = $g+1; // 게시물 번호
$n_table = substr($write_table,9);
$n_url = "./board.php?bo_table=$n_table&wr_id=".$n_wr_id;
$n_color = ($g + 70);
echo "<td width='20' style='cursor: pointer'><div style='background-color: #{$n_color}{$n_color}80' class='n_box' title='($n_date) $n_title[$g] [$n_comment]' onClick='location.href=\"$n_url\"' onMouseOver='this.style.backgroundColor=\"#a8a8a8\"' onMouseOut='this.style.backgroundColor=\"#{$n_color}{$n_color}80\"'>{$number}</div></td>";
}
echo "</tr>";
echo "</table>";
echo "</div>";
}
----------------------------------------------------------------
위 소스가 제가 구현하려는 기능입니다.
list.skin.php 파일에서 보면
<!-- 게시판 목록 시작 -->
<table width="<?=$width?>" align="center" cellpadding="0" cellspacing="0" class="bor-coll">
<tr height="25">
<td valign="bottom">
<!-- 분류 셀렉트 박스, 게시물 몇건, 관리자화면 링크 -->
<div class="board_top">
<div style="height:20px; float:left;">
<form name="fcategory" method="get" style="margin:0px;">
<? if ($is_category) { ?>
<select name=sca onchange="location='<?=$category_location?>'+this.value;" style="width:100px; height:20px">
<option value=''>전체</option>
<?=$category_option?>
</select>
<? } ?>
</form>
</div>
<div style="height:18px; float:right; padding: 1 2 0 0;">
<span style="color:#9d9d9d; font-family: tahoma; font-size:8pt;">Total <?=number_format($total_count)?></span>
<? if ($rss_href) { ?><a href='<?=$rss_href?>'><img src='<?=$board_skin_path?>/img/btn_rss.gif' border="0" align="absmiddle"></a><?}?>
<? if ($admin_href) { ?><a href="<?=$admin_href?>"><img src="<?=$board_skin_path?>/img/btn_admin.gif" title="관리자" align="absmiddle"></a><?}?>
</div>
이 부분 바로 다음에 시작합니다.
버퍼링 기능을 쓰지 않으면 위에 소스까지 브라우저가 출력하다가
제가 구현하려는 기능에 도착하면 db에서 뽑아내고 출력하는데
시간이 많이 걸리게 되는거죠. 이걸 무시하고 구현소스 바로 밑에부터
브라우저에 다~ 뿌리면 그때 저 구현기능 출력시키고 싶은겁니다.
ob_start(), ob_end_flush() 함수를 어느 위치에서
그리고 어떻게 써야 가능한지 궁금합니다.
이건 php.net에 가봐도 모르겠고, 다른 사람들이 올려놓은걸 봐도
설명이나 방법은 없고 그냥 어떻게 썻다 이런 얘기들뿐이라서요...
댓글 전체