묻고답하기
page_full_width" class="col-xs-12" |cond="$__Context->page_full_width">
php 게시판리스트 출력시 넘 느려요
2004.03.18 17:03
저희 사이트 게시판 에서 제일 많은 게시물이 테이블 하나에 3만건 정도 밖에 안되거든요?
근데 게시판 목록 한번 열라면 제일 느린 테이블은 거즘 7~8초
좀 나은건 약 1~2초 정도 걸립니다.
환장하겠습니다.
전에 외주줘서 만들었다는데요. 어떻게 손을 대야할지.. 걱정됩니다.
그래서 도움을 청합니다.
1. 게시판 테이블 구조
2. 게시판 목록을 불러올때 사용하는 함수
3. 게시판 목록 출력되는 부분
으로 나눠 정리 해보았습니다.
확인후 많은 분들 조언및 의견 부탁드립니다.
// 게시판 테이블 구조
CREATE TABLE TAB_Boardmnw (
BOD_Rowid int(11) NOT NULL auto_increment,
BOD_Memid varchar(12) NOT NULL default '',
BOD_Parent int(11) NOT NULL default '0',
BOD_Indent int(11) NOT NULL default '0',
BOD_Depth int(3) NOT NULL default '0',
BOD_Name varchar(32) NOT NULL default '',
BOD_Email varchar(64) NOT NULL default '',
BOD_Subject varchar(64) NOT NULL default '',
BOD_Sex char(2) NOT NULL default '',
BOD_Avata int(1) NOT NULL default '0',
BOD_Type char(1) NOT NULL default 'T',
BOD_Contents text NOT NULL,
BOD_Filename varchar(32) NOT NULL default '',
BOD_Hit int(11) NOT NULL default '0',
BOD_Opinion int(4) NOT NULL default '0',
BOD_Against int(4) NOT NULL default '0',
BOD_Date int(11) NOT NULL default '0',
PRIMARY KEY (BOD_Rowid),
KEY BOD_Memid (BOD_Memid),
KEY BOD_Parent (BOD_Parent),
KEY BOD_Indent (BOD_Indent),
KEY BOD_Email (BOD_Email)
) TYPE=MyISAM;
<?
// 함수 시작
function get_pagenum() {
global $board, $perpage;
include "config/db_conn.php3";
$result = mysql_query("SELECT COUNT(*) FROM $board");
$tlpn[num] = mysql_result($result, 0, "COUNT(*)");
if ($tlpn[num] % $perpage) {
$tlpn[page]= intval($tlpn[num] / $perpage) + 1;
}
else {
$tlpn[page]= $tlpn[num] / $perpage;
}
return $tlpn;
}
function arti_list($tlpn,$perpage)
{
include "config/db_conn.php3";
global $board, $page;
$result = lpp($tlpn, $perpage, $page);
return $result;
}
function lpp($tlpn, $perpage, $page) {
global $board;
include "config/db_conn.php3";
if (($tlpn[page] > $page) && ($page > 1)) { //******************* 중간페이지
$startlist = ($page * $perpage) - $perpage;
$result = mysql_query("SELECT * FROM $board ORDER BY BOD_Parent DESC, BOD_Indent ASC LIMIT $startlist,$perpage");
}
elseif ($page == 1) { // ***************************************** 첫 페이지라면..
if ($tlpn[num] >= $perpage) {
$result = mysql_query("SELECT * FROM $board ORDER BY BOD_Parent DESC, BOD_Indent ASC LIMIT 0,$perpage");
}
else {
$result = mysql_query("SELECT * FROM $board ORDER BY BOD_Parent DESC, BOD_Indent ASC LIMIT 0,$tlpn[num]");
}
}
elseif ($tlpn[page] == $page) { // ******************************** 맨 마지막 페이지라면..
if ($tlpn[num] % $perpage) {
$startlist = ($page * $perpage) - $perpage;
$result = mysql_query("SELECT * FROM $board ORDER BY BOD_Parent DESC, BOD_Indent ASC LIMIT $startlist,$perpage");
}
else {
$startlist = ($page * $perpage) - $perpage;
$result = mysql_query("SELECT * FROM $board ORDER BY BOD_Parent DESC, BOD_Indent ASC LIMIT $startlist,$perpage");
}
}
else {
echo "잘못된 페이지";
exit;
}
return $result;
}
?>
//게시판 목록 출력하는 스크립트
<?
$tlpn = get_pagenum();
$result = arti_list($tlpn,$perpage);
$q = ($page * $perpage) - $perpage;
$p = $tlpn[num] - $q;
while ($list = mysql_fetch_array($result)) {
$Nbsp = "";
$DEPTH_Img = "";
for ($j=0; $j < $list[BOD_Depth]; $j++) {
$Nbsp .= " ";
}
if ($list[BOD_Depth] > 0) {
$DEPTH_Img = "<img src="img/bbt_re.gif" border="0">";
}
if ($list[BOD_Email]) {
$BOD_Name = "<a href="mailto:$list[BOD_Email]">$list[BOD_Name]</a>";
}else {
$BOD_Name = $list[BOD_Name];
}
$BOD_Date = date("Y.m.d",$list[BOD_Date]);
$BOD_Subject = stripslashes($list[BOD_Subject]);
?>
<tr>
<td align="center" height="27"><?=$p?></td>
<td></td>
<td><?=$Nbsp?><?=$DEPTH_Img?><a href="board_mnw_view.html?BOD_Id=<?=$list[BOD_Rowid]?>&page=<?=$page?>"><?=$BOD_Subject?></a>
<!-- 의견글 카운트 -->
<?
$result1 = mysql_query("SELECT BOD_Rowid FROM TAB_Opinion WHERE BOD_Board='$board' AND BOD_Parent='$list[BOD_Rowid]'");
$O_Count = mysql_num_rows($result1);
if ($O_Count > 0) {
echo "( $O_Count )";
}
?>
<?
$OUT_Time = 60*60*24*1;
$TIME_Diff = time() - $list[BOD_Date];
if ($TIME_Diff < $OUT_Time) {echo " <img src='img/new.gif' align='absmiddle'>";}
?>
</td>
<td></td>
<td align="center"><?=$BOD_Name?></td>
<td></td>
<td align="center"><?=$list[BOD_Hit]?></td>
<td></td>
<td align="center"><font color="#999999"><?=$BOD_Date?></font></td>
<td></td>
<td align="center"><font color="#006600">
<?=$list[BOD_Opinion]?></font>/<font color="#CC0000"><?=$list[BOD_Against]?></font>
</td>
</tr>
<tr>
<td height="1" colspan="11" bgcolor="ECECEC"></td>
</tr>
<?$p--;}?>
근데 게시판 목록 한번 열라면 제일 느린 테이블은 거즘 7~8초
좀 나은건 약 1~2초 정도 걸립니다.
환장하겠습니다.
전에 외주줘서 만들었다는데요. 어떻게 손을 대야할지.. 걱정됩니다.
그래서 도움을 청합니다.
1. 게시판 테이블 구조
2. 게시판 목록을 불러올때 사용하는 함수
3. 게시판 목록 출력되는 부분
으로 나눠 정리 해보았습니다.
확인후 많은 분들 조언및 의견 부탁드립니다.
// 게시판 테이블 구조
CREATE TABLE TAB_Boardmnw (
BOD_Rowid int(11) NOT NULL auto_increment,
BOD_Memid varchar(12) NOT NULL default '',
BOD_Parent int(11) NOT NULL default '0',
BOD_Indent int(11) NOT NULL default '0',
BOD_Depth int(3) NOT NULL default '0',
BOD_Name varchar(32) NOT NULL default '',
BOD_Email varchar(64) NOT NULL default '',
BOD_Subject varchar(64) NOT NULL default '',
BOD_Sex char(2) NOT NULL default '',
BOD_Avata int(1) NOT NULL default '0',
BOD_Type char(1) NOT NULL default 'T',
BOD_Contents text NOT NULL,
BOD_Filename varchar(32) NOT NULL default '',
BOD_Hit int(11) NOT NULL default '0',
BOD_Opinion int(4) NOT NULL default '0',
BOD_Against int(4) NOT NULL default '0',
BOD_Date int(11) NOT NULL default '0',
PRIMARY KEY (BOD_Rowid),
KEY BOD_Memid (BOD_Memid),
KEY BOD_Parent (BOD_Parent),
KEY BOD_Indent (BOD_Indent),
KEY BOD_Email (BOD_Email)
) TYPE=MyISAM;
<?
// 함수 시작
function get_pagenum() {
global $board, $perpage;
include "config/db_conn.php3";
$result = mysql_query("SELECT COUNT(*) FROM $board");
$tlpn[num] = mysql_result($result, 0, "COUNT(*)");
if ($tlpn[num] % $perpage) {
$tlpn[page]= intval($tlpn[num] / $perpage) + 1;
}
else {
$tlpn[page]= $tlpn[num] / $perpage;
}
return $tlpn;
}
function arti_list($tlpn,$perpage)
{
include "config/db_conn.php3";
global $board, $page;
$result = lpp($tlpn, $perpage, $page);
return $result;
}
function lpp($tlpn, $perpage, $page) {
global $board;
include "config/db_conn.php3";
if (($tlpn[page] > $page) && ($page > 1)) { //******************* 중간페이지
$startlist = ($page * $perpage) - $perpage;
$result = mysql_query("SELECT * FROM $board ORDER BY BOD_Parent DESC, BOD_Indent ASC LIMIT $startlist,$perpage");
}
elseif ($page == 1) { // ***************************************** 첫 페이지라면..
if ($tlpn[num] >= $perpage) {
$result = mysql_query("SELECT * FROM $board ORDER BY BOD_Parent DESC, BOD_Indent ASC LIMIT 0,$perpage");
}
else {
$result = mysql_query("SELECT * FROM $board ORDER BY BOD_Parent DESC, BOD_Indent ASC LIMIT 0,$tlpn[num]");
}
}
elseif ($tlpn[page] == $page) { // ******************************** 맨 마지막 페이지라면..
if ($tlpn[num] % $perpage) {
$startlist = ($page * $perpage) - $perpage;
$result = mysql_query("SELECT * FROM $board ORDER BY BOD_Parent DESC, BOD_Indent ASC LIMIT $startlist,$perpage");
}
else {
$startlist = ($page * $perpage) - $perpage;
$result = mysql_query("SELECT * FROM $board ORDER BY BOD_Parent DESC, BOD_Indent ASC LIMIT $startlist,$perpage");
}
}
else {
echo "잘못된 페이지";
exit;
}
return $result;
}
?>
//게시판 목록 출력하는 스크립트
<?
$tlpn = get_pagenum();
$result = arti_list($tlpn,$perpage);
$q = ($page * $perpage) - $perpage;
$p = $tlpn[num] - $q;
while ($list = mysql_fetch_array($result)) {
$Nbsp = "";
$DEPTH_Img = "";
for ($j=0; $j < $list[BOD_Depth]; $j++) {
$Nbsp .= " ";
}
if ($list[BOD_Depth] > 0) {
$DEPTH_Img = "<img src="img/bbt_re.gif" border="0">";
}
if ($list[BOD_Email]) {
$BOD_Name = "<a href="mailto:$list[BOD_Email]">$list[BOD_Name]</a>";
}else {
$BOD_Name = $list[BOD_Name];
}
$BOD_Date = date("Y.m.d",$list[BOD_Date]);
$BOD_Subject = stripslashes($list[BOD_Subject]);
?>
<tr>
<td align="center" height="27"><?=$p?></td>
<td></td>
<td><?=$Nbsp?><?=$DEPTH_Img?><a href="board_mnw_view.html?BOD_Id=<?=$list[BOD_Rowid]?>&page=<?=$page?>"><?=$BOD_Subject?></a>
<!-- 의견글 카운트 -->
<?
$result1 = mysql_query("SELECT BOD_Rowid FROM TAB_Opinion WHERE BOD_Board='$board' AND BOD_Parent='$list[BOD_Rowid]'");
$O_Count = mysql_num_rows($result1);
if ($O_Count > 0) {
echo "( $O_Count )";
}
?>
<?
$OUT_Time = 60*60*24*1;
$TIME_Diff = time() - $list[BOD_Date];
if ($TIME_Diff < $OUT_Time) {echo " <img src='img/new.gif' align='absmiddle'>";}
?>
</td>
<td></td>
<td align="center"><?=$BOD_Name?></td>
<td></td>
<td align="center"><?=$list[BOD_Hit]?></td>
<td></td>
<td align="center"><font color="#999999"><?=$BOD_Date?></font></td>
<td></td>
<td align="center"><font color="#006600">
<?=$list[BOD_Opinion]?></font>/<font color="#CC0000"><?=$list[BOD_Against]?></font>
</td>
</tr>
<tr>
<td height="1" colspan="11" bgcolor="ECECEC"></td>
</tr>
<?$p--;}?>