Page execution time
Posted: Fri Aug 12, 2005 2:47 pm
I inserted some microtime()s in my forums, and I figured out where the main loading problem is.
As I figured, it's in my main loop. Each iteration through the loop is taking from .8 - 1.1 seconds
There are in total, 25 iterations of the loop per page load, and current page load time ranges from 18 - 25 seconds.
Perhaps someone could tell me where the time consuming part is.
This part generates the query:
Then here is my loop
As I figured, it's in my main loop. Each iteration through the loop is taking from .8 - 1.1 seconds
There are in total, 25 iterations of the loop per page load, and current page load time ranges from 18 - 25 seconds.
Perhaps someone could tell me where the time consuming part is.
This part generates the query:
Code: Select all
$sql_text = ("SELECT id, topicname, threadstatus, author FROM forumtopicmain WHERE forumid = '$forumid' AND type != 'sticky' ORDER BY lastreply DESC");
if(!$page)
{
$page = 1;
}
$prev_page = $page - 1;
$next_page = $page + 1;
$page_start = (25 * $page) - 25;
$query = mysql_query($sql_text);
$num_rows = mysql_num_rows($query);
if($num_rows <= 25)
{
$num_pages = 1;
} else if
(($num_rows % 25) == 0)
{
$num_pages = ($num_rows / 25);
} else
{
$num_pages = ($num_rows / 25) + 1;
}
$num_pages = (int) $num_pages;
if(($page > $num_pages) || ($page < 0))
{
die("You have specified an invalid page number");
}
$sql_text = $sql_text . " LIMIT $page_start, 25";
$query = mysql_query($sql_text);
// final result query looks like
// SELECT id, topicname, threadstatus, author FROM forumtopicmain WHERE forumid = '$forumid' AND type != 'sticky' ORDER BY lastreply DESC LIMIT 0, 25
?>Code: Select all
while($array = mysql_fetch_assoc($query))
{
$replies = mysql_num_rows(mysql_query("SELECT id FROM forumentries WHERE topicid = '".$array['id']."'")) - 1;
$lastpostarray = mysql_fetch_assoc(mysql_query("SELECT time, author FROM forumentries WHERE topicid = '".$array['id']."' ORDER BY time2 DESC LIMIT 1"));
// Show the number of pages for each individual topic
$query2 = mysql_query("SELECT id FROM forumentries WHERE topicid = '".$array['id']."'");
$numberofpages = (int)(((mysql_num_rows($query2) - 1)/25) + 2); ?>
<tr>
<td bgcolor="#E9EBFC" class="main" width="5%" align="center" style="border-left: solid 1px #000000; border-bottom: solid 1px #000000;">
<? if($array['threadstatus'] == "open"){ echo "<img src=\"images/thread_open.gif\" alt=\"Thread Open\">"; } ELSE { echo "<img src=\"images/thread_locked.gif\" alt=\"Thread Locked\">"; } ?>
</td>
<td bgcolor="#E9EBFC" class="main" width="45%" align="left" style="border-left: solid 1px #000000; border-bottom: solid 1px #000000;"><a href="showthread.php?threadid=<? echo $array['id']; ?>&page=1"><? echo stripslashes($array['topicname']); ?></a>
<? if($numberofpages > 2)
{
echo "<BR><font size=1>Page: </font>";
for ($j=1;$j<$numberofpages;$j++)
{
echo "<a href=\"showthread.php?threadid=".$array['id']."&page=$j\">$j</a> ";
}
} ?>
</td>
<td bgcolor="#E9EBFC" class="main" width="10%" align="center" style="border-left: solid 1px #000000; border-bottom: solid 1px #000000;"><B><? echo $replies; ?></B>
</td>
<td bgcolor="#E9EBFC" class="main" width="15%" align="center" style="border-left: solid 1px #000000; border-bottom: solid 1px #000000;"><a href="showme.php?u=<? echo $array['author']; ?>"><? echo $array['author']; ?></a>
</td>
<td bgcolor="#E9EBFC" class="main" width="25%" align="left" style="border-left: solid 1px #000000; border-bottom: solid 1px #000000; border-right: solid 1px #000000;"><? echo $lastpostarray['time']; ?><BR>by <a href="showme.php?u=<? echo $lastpostarray['author']; ?>"><? echo $lastpostarray['author']; ?></a>
</td>
</tr>
<? } ?>