Page 1 of 1

Insane loading time

Posted: Sat Jul 16, 2005 9:46 pm
by s.dot
Okay, I know I've posted about my forums in the past.

And now, the pages seem to load quickly.......... except for one.

It's the showforum.php page

Someone tell me if anything sticks out like a sore thumb.. that would slow my page loading time wayyyyyy down. I'm looking at like 10 seconds every time I load this page. Maybe it's because I escape to HTML too much?

Code: Select all

<?
$description = "Browse forum topics";
require 'header.php';

// Update doing section
if(isset($_COOKIE['username']))
{
	mysql_query("UPDATE users SET doing = 'Browsing Forums' WHERE username = '$theperson'");
}

// Administration

// Lock thread
if($_POST['action'] == "lockthread")
{
	$threadtolock = mysql_real_escape_string(strip_tags($_POST['threadtolock']));
	$adminarray = array("scrotaye", "artbalaoro", "potato", "magicflymonkey");
	if(in_array($theperson, $adminarray))
	{
		mysql_query("UPDATE forumtopicmain SET threadstatus = 'locked' WHERE id = '$threadtolock'");
		mysql_query("UPDATE forumentries SET threadstatus = 'locked' WHERE topicid = '$threadtolock'");
		echo "<p align=center><B>Thread has been locked.</B></p>";
	}
}

// Move topic
if($_POST['action'] == "movetopic")
{
	$topictomove2 = mysql_real_escape_string(strip_tags($_POST['topictomove2']));
	$topictomove = mysql_real_escape_string(strip_tags($_POST['topictomove']));
	$adminarray = array("scrotaye", "artbalaoro", "potato", "magicflymonkey");
	if(in_array($_COOKIE['username'], $adminarray))
	{
		mysql_query("UPDATE forumtopicmain SET forumid = '$topictomove' WHERE id = '$topictomove2'");
		$movedrepliesquery = mysql_query("SELECT id FROM forumentries WHERE topicid = '$topictomove2'");
		while($movedrepliesarray = mysql_fetch_array($movedrepliesquery))
		{
			mysql_query("UPDATE forumentries SET forumid = '$topictomove' WHERE topicid = '$topictomove2'");
		}
		echo "<p align=center><B>Topic has been moved.</B></p>";
	}
}

// End administration

// Purify $_GET information
$forumid = mysql_real_escape_string(strip_tags($forumid));

// Select the forum name
$forumarray = mysql_fetch_assoc(mysql_query("SELECT topicname FROM forumtopics WHERE id = '$forumid'"));

// Begin pagination for main page
$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); ?>

<a href="forums.php">Show My Pro Forums</a> > <a href="showforum.php?forumid=<? echo $forumid; ?>"><? echo $forumarray['topicname']; ?></a> > <a href="newforumtopic.php?forumid=<? echo $forumid; ?>"><img src="images/newtopic.gif" alt="New Topic" border="0"></a>
<table width="100%" cellspacing="0" cellpadding="3" style="border: solid 1px #000000">
	<tr>
		<td style="border: solid 1px #000000" align="center" colspan="5" bgcolor="#CCCCCC"><B><font size="2">A Space For Your Thoughts</font></B>
		</td>
	</tr>
	<tr>
		<td style="border: solid 1px #000000" align="center" width="5%" bgcolor="#CCCCCC">&nbsp;
		</td>
		<td style="border: solid 1px #000000" align="center" width="50%" bgcolor="#CCCCCC"><B><font size="2">Topic</font></B>
		</td>
		<td style="border: solid 1px #000000" align="center" width="10%" bgcolor="#CCCCCC"><B><font size="2">Replies</font></B>
		</td>
		<td style="border: solid 1px #000000" align="center" width="15%" bgcolor="#CCCCCC"><B><font size="2">Author</font></B>
		</td>
		<td style="border: solid 1px #000000" align="center" width="20%" bgcolor="#CCCCCC"><B><font size="2">Last Post</font></B>
		</td>
	</tr>
<? 

// Show stickies first
if($page == "1")
{
	$stickyquery = mysql_query("SELECT id, topicname, threadstatus, author FROM forumtopicmain WHERE forumid = '$forumid' AND type = 'sticky' ORDER BY lastreply DESC");
	while($stickyarray = mysql_fetch_assoc($stickyquery))
	{
		$stickyquery2 = mysql_query("SELECT id FROM forumentries WHERE topicid = '".$stickyarray['id']."'");
		$stickyreplies = mysql_num_rows($stickyquery2) - 1;
		$stickylastpostarray = mysql_fetch_assoc(mysql_query("SELECT time, author FROM forumentries WHERE topicid = '".$stickyarray['id']."' ORDER BY time2 DESC LIMIT 1")); ?>
	<tr>
		<td style="border: solid 1px #000000" width="5%" align="center"><? if($stickyarray['threadstatus'] == "open"){ ?><img src="images/thread_open.gif"><? } ELSE { ?><img src="images/thread_locked.gif"> <? } ?>
		</td>
		<td style="border: solid 1px #000000" width="50%" align="left"><a href="showthread.php?threadid=<? echo $stickyarray['id']; ?>&page=1"><? echo "STICKY: ".stripslashes($stickyarray['topicname']).""; ?></a>
		</td>
		<td style="border: solid 1px #000000" width="10%" align="center"><B><font size="2"><? echo $stickyreplies; ?></B>
		</td>
		<td style="border: solid 1px #000000" width="15%" align="center"><a href="showme.php?u=<? echo $stickyarray['author']; ?>"><? echo $stickyarray['author']; ?></a>
		</td>
		<td style="border: solid 1px #000000" width="20%" align="left"><font size="2"><? echo $stickylastpostarray['time']; ?></font><BR><font size="2">by</font> <a href="showme.php?u=<? echo $stickylastpostarray['author']; ?>"><? echo $stickylastpostarray['author']; ?></a>
		</td>
	</tr>
<?
	}
}


// Show the non-stickied topics (most of them)
while($array = mysql_fetch_assoc($query))
{ 
	$query2 = mysql_query("SELECT id FROM forumentries WHERE topicid = '".$array['id']."'");
	$replies = mysql_num_rows($query2) - 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
	$sql_text2 = ("SELECT id FROM forumentries WHERE topicid = '".$array['id']."'");
	$query2 = mysql_query($sql_text2);
	$page_start2 = (25 * $page2) - 25; 
	$num_rows2 = mysql_num_rows($query2); 
	if ($num_rows2 <= 25) { $num_pages2 = 1; } else if
	(($num_rows2 % 25) == 0) { $num_pages2 = ($num_rows2 / 25); } else {
	$num_pages2 = ($num_rows2 / 25) + 1; }
	$num_pages2 = (int) $num_pages2; 
	$sql_text2 = $sql_text2 . " LIMIT $page_start2, 25"; ?>
	<tr>
		<td style="border: solid 1px #000000" width="5%" align="center"><? if($array['threadstatus'] == "open"){ ?><img src="images/thread_open.gif"><? } ELSE { ?><img src="images/thread_locked.gif"> <? } ?>
		</td>
		<td style="border: solid 1px #000000" width="50%" align="left"><a href="showthread.php?threadid=<? echo $array['id']; ?>&page=1"><? echo stripslashes($array['topicname']); ?></a><? if($num_pages2 > 1){ echo "<BR><font size=1>Page: </font>"; for ($i = 1; $i <= $num_pages2; $i++) {echo "<a href=\"showthread.php?threadid=".$array['id']."&page=$i\"><font size=1>$i</font></a> "; } } ?>
		</td>
		<td style="border: solid 1px #000000" width="10%" align="center"><B><font size="2"><? echo $replies; ?></B>
		</td>
		<td style="border: solid 1px #000000" width="15%" align="center"><a href="showme.php?u=<? echo $array['author']; ?>"><? echo $array['author']; ?></a>
		</td>
		<td style="border: solid 1px #000000" width="20%" align="left"><font size="2"><? echo $lastpostarray['time']; ?></font><BR><font size="2">by</font> <a href="showme.php?u=<? echo $lastpostarray['author']; ?>"><? echo $lastpostarray['author']; ?></a>
		</td>
	</tr><?
} ?>
</table>
<a href="forums.php">Show My Pro Forums</a> > <a href="showforum.php?forumid=<? echo $forumid; ?>"><? echo $forumarray['topicname']; ?></a> > <a href="newforumtopic.php?forumid=<? echo $forumid; ?>"><img src="images/newtopic.gif" alt="New Topic" border="0"></a>
<p class="main"><center>
<?
// Show next 10 pages, previous 10 pages, etc.. for the number of pages in the forum
$limit = $page+10;
if($num_pages >= $limit)
{
	if($page != 1)
	{
	$previouspage = $page - 1;
	$previousstart = $previouspage - 9;
		if($page == 2)
		{
			echo "<small><<</small> <a href=\"$PHP_SELF?forumid=$forumid&page=1\">Page 1</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
		} ELSE
		{
			if($previousstart <= 0)
			{
				echo"<small><<</small> <a href=\"$PHP_SELF?forumid=$forumid&page=1\">Pages 1 - $previouspage</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
			} ELSE
			{
				echo "<small><<</small> <a href=\"$PHP_SELF?forumid=$forumid&page=$previousstart\">Pages $previousstart - $previouspage</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
			}
		}
	}
	for($i = $page; $i<$limit; $i++)
	{
		echo " <a href=\"$PHP_SELF?forumid=$forumid&page=$i\">$i</a> ";
	}
	$limit2 = $i+9;
	if($num_pages <= $limit2)
	{
		echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href=\"$PHP_SELEF?forumid=$forumid&page=$i\">Pages $i - $num_pages</a> <small>>></small>";
	} ELSE
	{
		echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href=\"$PHP_SELEF?forumid=$forumid&page=$i\">Pages $i - $limit2</a> <small>>></small>";
	}
} ELSE
{
	for($i = $page; $i<=$num_pages; $i++)
	{
		echo " <a href=\"$PHP_SELF?forumid=$forumid&page=$i\">$i</a> ";
	}
}
?>
</center></p>
<p align="left" class="main"><img src="images/to_e.gif"> Thread Open&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<img src="images/tl_e.gif"> Thread Locked</font></p>

<?
// Start administration panel
$adminarray = array("scrotaye", "artbalaoro", "potato", "magicflymonkey");
if(in_array($_COOKIE['username'], $adminarray))
	{
?>
<table width="60%" align="center" style="border: solid 1px #000000" cellspacing="0" cellpading="3">
	<tr>
		<td style="border: solid 1px #000000" align="center" bgcolor="#CCCCCC"><B><font size="2">Administration Panel</font></B>
		</td>
	</tr>
	<tr>
		<td style="border: solid 1px #000000" align="center">
<form action="showforum.php?forumid=<? echo $forumid; ?>" method="post">
<input type="hidden" name="action" value="lockthread">
<p align="center"><B><font size="2">Lock Thread</font></B><BR>
<select name="threadtolock">
<option selected>Select</option><?
$threadtolockquery = mysql_query("SELECT id, topicname FROM forumtopicmain WHERE forumid = '$forumid' ORDER BY lastreply DESC LIMIT 25");
while($threadtolockarray = mysql_fetch_assoc($threadtolockquery))
	{ ?>
	<option value="<? echo $threadtolockarray['id']; ?>"><? echo stripslashes($threadtolockarray['topicname']); ?></option><?
	} ?>
</select>
<BR>
<input type="submit" value="Lock">
</form>
<form action="showforum.php?forumid=<? echo $forumid; ?>" method="post">
<input type="hidden" name="action" value="movetopic">
<p align="center"><B><font size="2">Move Topic</font></B></p>
<B><font size="2">Move Topic Named</font></B>
<select name="topictomove2">
<option selected>Select</option><?
$threadtomovequery = mysql_query("SELECT id, topicname FROM forumtopicmain WHERE forumid = '$forumid' ORDER BY lastreply DESC LIMIT 25");
while($threadtomovearray = mysql_fetch_assoc($threadtomovequery)){
?><option value="<? echo $threadtomovearray['id']; ?>"><? echo stripslashes($threadtomovearray['topicname']); ?></option>
<?
} ?>
</select><BR><B><font size="2">To Forum</font></B><BR>
<select name="topictomove">
<option selected>Select</option><?
$topicsmovequery = mysql_query("SELECT topicname, id FROM forumtopics ORDER BY rank");
while($topicsmovearray = mysql_fetch_assoc($topicsmovequery)){ ?>
<option value="<? echo $topicsmovearray['id']; ?>"><? echo $topicsmovearray['topicname']; ?></option><? } ?>
</select><BR>
<input type="submit" value="Move">
</form>
		</td>
	</tr>
</table><?
}

require 'footer.php'; ?>
Live example: http://www.showmypro.com/showforum.php?forumid=1ast.

And now, the pages seem to load quickly.......... except for one.

It's the showforum.php page

Someone tell me if anything sticks out like a sore thumb.. that would slow my page loading time wayyyyyy down. I'm looking at like 10 seconds every time I load this page. Maybe it's because I escape to HTML too much?

Code: Select all

&lt;?
$description = &quote;Browse forum topics&quote;;
require 'header.php';

// Update doing section
if(isset($_COOKIE&#1111;'username']))
{
	mysql_query(&quote;UPDATE users SET doing = 'Browsing Forums' WHERE username = '$theperson'&quote;);
}

// Administration

// Lock thread
if($_POST&#1111;'action'] == &quote;lockthread&quote;)
{
	$threadtolock = mysql_real_escape_string(strip_tags($_POST&#1111;'threadtolock']));
	$adminarray = array(&quote;scrotaye&quote;, &quote;artbalaoro&quote;, &quote;potato&quote;, &quote;magicflymonkey&quote;);
	if(in_array($theperson, $adminarray))
	{
		mysql_query(&quote;UPDATE forumtopicmain SET threadstatus = 'locked' WHERE id = '$threadtolock'&quote;);
		mysql_query(&quote;UPDATE forumentries SET threadstatus = 'locked' WHERE topicid = '$threadtolock'&quote;);
		echo &quote;&lt;p align=center&gt;&lt;B&gt;Thread has been locked.&lt;/B&gt;&lt;/p&gt;&quote;;
	}
}

// Move topic
if($_POST&#1111;'action'] == &quote;movetopic&quote;)
{
	$topictomove2 = mysql_real_escape_string(strip_tags($_POST&#1111;'topictomove2']));
	$topictomove = mysql_real_escape_string(strip_tags($_POST&#1111;'topictomove']));
	$adminarray = array(&quote;scrotaye&quote;, &quote;artbalaoro&quote;, &quote;potato&quote;, &quote;magicflymonkey&quote;);
	if(in_array($_COOKIE&#1111;'username'], $adminarray))
	{
		mysql_query(&quote;UPDATE forumtopicmain SET forumid = '$topictomove' WHERE id = '$topictomove2'&quote;);
		$movedrepliesquery = mysql_query(&quote;SELECT id FROM forumentries WHERE topicid = '$topictomove2'&quote;);
		while($movedrepliesarray = mysql_fetch_array($movedrepliesquery))
		{
			mysql_query(&quote;UPDATE forumentries SET forumid = '$topictomove' WHERE topicid = '$topictomove2'&quote;);
		}
		echo &quote;&lt;p align=center&gt;&lt;B&gt;Topic has been moved.&lt;/B&gt;&lt;/p&gt;&quote;;
	}
}

// End administration

// Purify $_GET information
$forumid = mysql_real_escape_string(strip_tags($forumid));

// Select the forum name
$forumarray = mysql_fetch_assoc(mysql_query(&quote;SELECT topicname FROM forumtopics WHERE id = '$forumid'&quote;));

// Begin pagination for main page
$sql_text = (&quote;SELECT id, topicname, threadstatus, author FROM forumtopicmain WHERE forumid = '$forumid' AND type != 'sticky' ORDER BY lastreply DESC&quote;);
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 &lt;= 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 &gt; $num_pages) || ($page &lt; 0))
{
	die(&quote;You have specified an invalid page number&quote;);
}
$sql_text = $sql_text . &quote; LIMIT $page_start, 25&quote;; 
$query = mysql_query($sql_text); ?&gt;

&lt;a href=&quote;forums.php&quote;&gt;Show My Pro Forums&lt;/a&gt; &gt; &lt;a href=&quote;showforum.php?forumid=&lt;? echo $forumid; ?&gt;&quote;&gt;&lt;? echo $forumarray&#1111;'topicname']; ?&gt;&lt;/a&gt; &gt; &lt;a href=&quote;newforumtopic.php?forumid=&lt;? echo $forumid; ?&gt;&quote;&gt;&lt;img src=&quote;images/newtopic.gif&quote; alt=&quote;New Topic&quote; border=&quote;0&quote;&gt;&lt;/a&gt;
&lt;table width=&quote;100%&quote; cellspacing=&quote;0&quote; cellpadding=&quote;3&quote; style=&quote;border: solid 1px #000000&quote;&gt;
	&lt;tr&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; align=&quote;center&quote; colspan=&quote;5&quote; bgcolor=&quote;#CCCCCC&quote;&gt;&lt;B&gt;&lt;font size=&quote;2&quote;&gt;A Space For Your Thoughts&lt;/font&gt;&lt;/B&gt;
		&lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; align=&quote;center&quote; width=&quote;5%&quote; bgcolor=&quote;#CCCCCC&quote;&gt;&amp;nbsp;
		&lt;/td&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; align=&quote;center&quote; width=&quote;50%&quote; bgcolor=&quote;#CCCCCC&quote;&gt;&lt;B&gt;&lt;font size=&quote;2&quote;&gt;Topic&lt;/font&gt;&lt;/B&gt;
		&lt;/td&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; align=&quote;center&quote; width=&quote;10%&quote; bgcolor=&quote;#CCCCCC&quote;&gt;&lt;B&gt;&lt;font size=&quote;2&quote;&gt;Replies&lt;/font&gt;&lt;/B&gt;
		&lt;/td&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; align=&quote;center&quote; width=&quote;15%&quote; bgcolor=&quote;#CCCCCC&quote;&gt;&lt;B&gt;&lt;font size=&quote;2&quote;&gt;Author&lt;/font&gt;&lt;/B&gt;
		&lt;/td&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; align=&quote;center&quote; width=&quote;20%&quote; bgcolor=&quote;#CCCCCC&quote;&gt;&lt;B&gt;&lt;font size=&quote;2&quote;&gt;Last Post&lt;/font&gt;&lt;/B&gt;
		&lt;/td&gt;
	&lt;/tr&gt;
&lt;? 

// Show stickies first
if($page == &quote;1&quote;)
{
	$stickyquery = mysql_query(&quote;SELECT id, topicname, threadstatus, author FROM forumtopicmain WHERE forumid = '$forumid' AND type = 'sticky' ORDER BY lastreply DESC&quote;);
	while($stickyarray = mysql_fetch_assoc($stickyquery))
	{
		$stickyquery2 = mysql_query(&quote;SELECT id FROM forumentries WHERE topicid = '&quote;.$stickyarray&#1111;'id'].&quote;'&quote;);
		$stickyreplies = mysql_num_rows($stickyquery2) - 1;
		$stickylastpostarray = mysql_fetch_assoc(mysql_query(&quote;SELECT time, author FROM forumentries WHERE topicid = '&quote;.$stickyarray&#1111;'id'].&quote;' ORDER BY time2 DESC LIMIT 1&quote;)); ?&gt;
	&lt;tr&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; width=&quote;5%&quote; align=&quote;center&quote;&gt;&lt;? if($stickyarray&#1111;'threadstatus'] == &quote;open&quote;){ ?&gt;&lt;img src=&quote;images/thread_open.gif&quote;&gt;&lt;? } ELSE { ?&gt;&lt;img src=&quote;images/thread_locked.gif&quote;&gt; &lt;? } ?&gt;
		&lt;/td&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; width=&quote;50%&quote; align=&quote;left&quote;&gt;&lt;a href=&quote;showthread.php?threadid=&lt;? echo $stickyarray&#1111;'id']; ?&gt;&amp;page=1&quote;&gt;&lt;? echo &quote;STICKY: &quote;.stripslashes($stickyarray&#1111;'topicname']).&quote;&quote;; ?&gt;&lt;/a&gt;
		&lt;/td&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; width=&quote;10%&quote; align=&quote;center&quote;&gt;&lt;B&gt;&lt;font size=&quote;2&quote;&gt;&lt;? echo $stickyreplies; ?&gt;&lt;/B&gt;
		&lt;/td&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; width=&quote;15%&quote; align=&quote;center&quote;&gt;&lt;a href=&quote;showme.php?u=&lt;? echo $stickyarray&#1111;'author']; ?&gt;&quote;&gt;&lt;? echo $stickyarray&#1111;'author']; ?&gt;&lt;/a&gt;
		&lt;/td&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; width=&quote;20%&quote; align=&quote;left&quote;&gt;&lt;font size=&quote;2&quote;&gt;&lt;? echo $stickylastpostarray&#1111;'time']; ?&gt;&lt;/font&gt;&lt;BR&gt;&lt;font size=&quote;2&quote;&gt;by&lt;/font&gt; &lt;a href=&quote;showme.php?u=&lt;? echo $stickylastpostarray&#1111;'author']; ?&gt;&quote;&gt;&lt;? echo $stickylastpostarray&#1111;'author']; ?&gt;&lt;/a&gt;
		&lt;/td&gt;
	&lt;/tr&gt;
&lt;?
	}
}


// Show the non-stickied topics (most of them)
while($array = mysql_fetch_assoc($query))
{ 
	$query2 = mysql_query(&quote;SELECT id FROM forumentries WHERE topicid = '&quote;.$array&#1111;'id'].&quote;'&quote;);
	$replies = mysql_num_rows($query2) - 1;
	$lastpostarray = mysql_fetch_assoc(mysql_query(&quote;SELECT time, author FROM forumentries WHERE topicid = '&quote;.$array&#1111;'id'].&quote;' ORDER BY time2 DESC LIMIT 1&quote;));

	// Show the number of pages for each individual topic
	$sql_text2 = (&quote;SELECT id FROM forumentries WHERE topicid = '&quote;.$array&#1111;'id'].&quote;'&quote;);
	$query2 = mysql_query($sql_text2);
	$page_start2 = (25 * $page2) - 25; 
	$num_rows2 = mysql_num_rows($query2); 
	if ($num_rows2 &lt;= 25) { $num_pages2 = 1; } else if
	(($num_rows2 % 25) == 0) { $num_pages2 = ($num_rows2 / 25); } else {
	$num_pages2 = ($num_rows2 / 25) + 1; }
	$num_pages2 = (int) $num_pages2; 
	$sql_text2 = $sql_text2 . &quote; LIMIT $page_start2, 25&quote;; ?&gt;
	&lt;tr&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; width=&quote;5%&quote; align=&quote;center&quote;&gt;&lt;? if($array&#1111;'threadstatus'] == &quote;open&quote;){ ?&gt;&lt;img src=&quote;images/thread_open.gif&quote;&gt;&lt;? } ELSE { ?&gt;&lt;img src=&quote;images/thread_locked.gif&quote;&gt; &lt;? } ?&gt;
		&lt;/td&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; width=&quote;50%&quote; align=&quote;left&quote;&gt;&lt;a href=&quote;showthread.php?threadid=&lt;? echo $array&#1111;'id']; ?&gt;&amp;page=1&quote;&gt;&lt;? echo stripslashes($array&#1111;'topicname']); ?&gt;&lt;/a&gt;&lt;? if($num_pages2 &gt; 1){ echo &quote;&lt;BR&gt;&lt;font size=1&gt;Page: &lt;/font&gt;&quote;; for ($i = 1; $i &lt;= $num_pages2; $i++) {echo &quote;&lt;a href=\&quote;showthread.php?threadid=&quote;.$array&#1111;'id'].&quote;&amp;page=$i\&quote;&gt;&lt;font size=1&gt;$i&lt;/font&gt;&lt;/a&gt; &quote;; } } ?&gt;
		&lt;/td&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; width=&quote;10%&quote; align=&quote;center&quote;&gt;&lt;B&gt;&lt;font size=&quote;2&quote;&gt;&lt;? echo $replies; ?&gt;&lt;/B&gt;
		&lt;/td&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; width=&quote;15%&quote; align=&quote;center&quote;&gt;&lt;a href=&quote;showme.php?u=&lt;? echo $array&#1111;'author']; ?&gt;&quote;&gt;&lt;? echo $array&#1111;'author']; ?&gt;&lt;/a&gt;
		&lt;/td&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; width=&quote;20%&quote; align=&quote;left&quote;&gt;&lt;font size=&quote;2&quote;&gt;&lt;? echo $lastpostarray&#1111;'time']; ?&gt;&lt;/font&gt;&lt;BR&gt;&lt;font size=&quote;2&quote;&gt;by&lt;/font&gt; &lt;a href=&quote;showme.php?u=&lt;? echo $lastpostarray&#1111;'author']; ?&gt;&quote;&gt;&lt;? echo $lastpostarray&#1111;'author']; ?&gt;&lt;/a&gt;
		&lt;/td&gt;
	&lt;/tr&gt;&lt;?
} ?&gt;
&lt;/table&gt;
&lt;a href=&quote;forums.php&quote;&gt;Show My Pro Forums&lt;/a&gt; &gt; &lt;a href=&quote;showforum.php?forumid=&lt;? echo $forumid; ?&gt;&quote;&gt;&lt;? echo $forumarray&#1111;'topicname']; ?&gt;&lt;/a&gt; &gt; &lt;a href=&quote;newforumtopic.php?forumid=&lt;? echo $forumid; ?&gt;&quote;&gt;&lt;img src=&quote;images/newtopic.gif&quote; alt=&quote;New Topic&quote; border=&quote;0&quote;&gt;&lt;/a&gt;
&lt;p class=&quote;main&quote;&gt;&lt;center&gt;
&lt;?
// Show next 10 pages, previous 10 pages, etc.. for the number of pages in the forum
$limit = $page+10;
if($num_pages &gt;= $limit)
{
	if($page != 1)
	{
	$previouspage = $page - 1;
	$previousstart = $previouspage - 9;
		if($page == 2)
		{
			echo &quote;&lt;small&gt;&lt;&lt;&lt;/small&gt; &lt;a href=\&quote;$PHP_SELF?forumid=$forumid&amp;page=1\&quote;&gt;Page 1&lt;/a&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&quote;;
		} ELSE
		{
			if($previousstart &lt;= 0)
			{
				echo&quote;&lt;small&gt;&lt;&lt;&lt;/small&gt; &lt;a href=\&quote;$PHP_SELF?forumid=$forumid&amp;page=1\&quote;&gt;Pages 1 - $previouspage&lt;/a&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&quote;;
			} ELSE
			{
				echo &quote;&lt;small&gt;&lt;&lt;&lt;/small&gt; &lt;a href=\&quote;$PHP_SELF?forumid=$forumid&amp;page=$previousstart\&quote;&gt;Pages $previousstart - $previouspage&lt;/a&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&quote;;
			}
		}
	}
	for($i = $page; $i&lt;$limit; $i++)
	{
		echo &quote; &lt;a href=\&quote;$PHP_SELF?forumid=$forumid&amp;page=$i\&quote;&gt;$i&lt;/a&gt; &quote;;
	}
	$limit2 = $i+9;
	if($num_pages &lt;= $limit2)
	{
		echo &quote;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;a href=\&quote;$PHP_SELEF?forumid=$forumid&amp;page=$i\&quote;&gt;Pages $i - $num_pages&lt;/a&gt; &lt;small&gt;&gt;&gt;&lt;/small&gt;&quote;;
	} ELSE
	{
		echo &quote;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;a href=\&quote;$PHP_SELEF?forumid=$forumid&amp;page=$i\&quote;&gt;Pages $i - $limit2&lt;/a&gt; &lt;small&gt;&gt;&gt;&lt;/small&gt;&quote;;
	}
} ELSE
{
	for($i = $page; $i&lt;=$num_pages; $i++)
	{
		echo &quote; &lt;a href=\&quote;$PHP_SELF?forumid=$forumid&amp;page=$i\&quote;&gt;$i&lt;/a&gt; &quote;;
	}
}
?&gt;
&lt;/center&gt;&lt;/p&gt;
&lt;p align=&quote;left&quote; class=&quote;main&quote;&gt;&lt;img src=&quote;images/to_e.gif&quote;&gt; Thread Open&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;img src=&quote;images/tl_e.gif&quote;&gt; Thread Locked&lt;/font&gt;&lt;/p&gt;

&lt;?
// Start administration panel
$adminarray = array(&quote;scrotaye&quote;, &quote;artbalaoro&quote;, &quote;potato&quote;, &quote;magicflymonkey&quote;);
if(in_array($_COOKIE&#1111;'username'], $adminarray))
	{
?&gt;
&lt;table width=&quote;60%&quote; align=&quote;center&quote; style=&quote;border: solid 1px #000000&quote; cellspacing=&quote;0&quote; cellpading=&quote;3&quote;&gt;
	&lt;tr&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; align=&quote;center&quote; bgcolor=&quote;#CCCCCC&quote;&gt;&lt;B&gt;&lt;font size=&quote;2&quote;&gt;Administration Panel&lt;/font&gt;&lt;/B&gt;
		&lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; align=&quote;center&quote;&gt;
&lt;form action=&quote;showforum.php?forumid=&lt;? echo $forumid; ?&gt;&quote; method=&quote;post&quote;&gt;
&lt;input type=&quote;hidden&quote; name=&quote;action&quote; value=&quote;lockthread&quote;&gt;
&lt;p align=&quote;center&quote;&gt;&lt;B&gt;&lt;font size=&quote;2&quote;&gt;Lock Thread&lt;/font&gt;&lt;/B&gt;&lt;BR&gt;
&lt;select name=&quote;threadtolock&quote;&gt;
&lt;option selected&gt;Select&lt;/option&gt;&lt;?
$threadtolockquery = mysql_query(&quote;SELECT id, topicname FROM forumtopicmain WHERE forumid = '$forumid' ORDER BY lastreply DESC LIMIT 25&quote;);
while($threadtolockarray = mysql_fetch_assoc($threadtolockquery))
	{ ?&gt;
	&lt;option value=&quote;&lt;? echo $threadtolockarray&#1111;'id']; ?&gt;&quote;&gt;&lt;? echo stripslashes($threadtolockarray&#1111;'topicname']); ?&gt;&lt;/option&gt;&lt;?
	} ?&gt;
&lt;/select&gt;
&lt;BR&gt;
&lt;input type=&quote;submit&quote; value=&quote;Lock&quote;&gt;
&lt;/form&gt;
&lt;form action=&quote;showforum.php?forumid=&lt;? echo $forumid; ?&gt;&quote; method=&quote;post&quote;&gt;
&lt;input type=&quote;hidden&quote; name=&quote;action&quote; value=&quote;movetopic&quote;&gt;
&lt;p align=&quote;center&quote;&gt;&lt;B&gt;&lt;font size=&quote;2&quote;&gt;Move Topic&lt;/font&gt;&lt;/B&gt;&lt;/p&gt;
&lt;B&gt;&lt;font size=&quote;2&quote;&gt;Move Topic Named&lt;/font&gt;&lt;/B&gt;
&lt;select name=&quote;topictomove2&quote;&gt;
&lt;option selected&gt;Select&lt;/option&gt;&lt;?
$threadtomovequery = mysql_query(&quote;SELECT id, topicname FROM forumtopicmain WHERE forumid = '$forumid' ORDER BY lastreply DESC LIMIT 25&quote;);
while($threadtomovearray = mysql_fetch_assoc($threadtomovequery)){
?&gt;&lt;option value=&quote;&lt;? echo $threadtomovearray&#1111;'id']; ?&gt;&quote;&gt;&lt;? echo stripslashes($threadtomovearray&#1111;'topicname']); ?&gt;&lt;/option&gt;
&lt;?
} ?&gt;
&lt;/select&gt;&lt;BR&gt;&lt;B&gt;&lt;font size=&quote;2&quote;&gt;To Forum&lt;/font&gt;&lt;/B&gt;&lt;BR&gt;
&lt;select name=&quote;topictomove&quote;&gt;
&lt;option selected&gt;Select&lt;/option&gt;&lt;?
$topicsmovequery = mysql_query(&quote;SELECT topicname, id FROM forumtopics ORDER BY rank&quote;);
while($topicsmovearray = mysql_fetch_assoc($topicsmovequery)){ ?&gt;
&lt;option value=&quote;&lt;? echo $topicsmovearray&#1111;'id']; ?&gt;&quote;&gt;&lt;? echo $topicsmovearray&#1111;'topicname']; ?&gt;&lt;/option&gt;&lt;? } ?&gt;
&lt;/select&gt;&lt;BR&gt;
&lt;input type=&quote;submit&quote; value=&quote;Move&quote;&gt;
&lt;/form&gt;
		&lt;/td&gt;
	&quickly.......... except for one.

It's the showforum.php page

Someone tell me if anything sticks out like a sore thumb.. that would slow my page loading time wayyyyyy down.  I'm looking at like 10 seconds every time I load this page.  Maybe it's because I escape to HTML too much?

Code: Select all

<?
$description = "Browse forum topics&quote;;
require 'header.php';

// Update doing section
if(isset($_COOKIE&#1111;'username']))
{
	mysql_query(&quote;UPDATE users SET doing = 'Browsing Forums' WHERE username = '$theperson'&quote;);
}

// Administration

// Lock thread
if($_POST&#1111;'action'] == &quote;lockthread&quote;)
{
	$threadtolock = mysql_real_escape_string(strip_tags($_POST&#1111;'threadtolock']));
	$adminarray = array(&quote;scrotaye&quote;, &quote;artbalaoro&quote;, &quote;potato&quote;, &quote;magicflymonkey&quote;);
	if(in_array($theperson, $adminarray))
	{
		mysql_query(&quote;UPDATE forumtopicmain SET threadstatus = 'locked' WHERE id = '$threadtolock'&quote;);
		mysql_query(&quote;UPDATE forumentries SET threadstatus = 'locked' WHERE topicid = '$threadtolock'&quote;);
		echo &quote;&lt;p align=center&gt;&lt;B&gt;Thread has been locked.&lt;/B&gt;&lt;/p&gt;&quote;;
	}
}

// Move topic
if($_POST&#1111;'action'] == &quote;movetopic&quote;)
{
	$topictomove2 = mysql_real_escape_string(strip_tags($_POST&#1111;'topictomove2']));
	$topictomove = mysql_real_escape_string(strip_tags($_POST&#1111;'topictomove']));
	$adminarray = array(&quote;scrotaye&quote;, &quote;artbalaoro&quote;, &quote;potato&quote;, &quote;magicflymonkey&quote;);
	if(in_array($_COOKIE&#1111;'username'], $adminarray))
	{
		mysql_query(&quote;UPDATE forumtopicmain SET forumid = '$topictomove' WHERE id = '$topictomove2'&quote;);
		$movedrepliesquery = mysql_query(&quote;SELECT id FROM forumentries WHERE topicid = '$topictomove2'&quote;);
		while($movedrepliesarray = mysql_fetch_array($movedrepliesquery))
		{
			mysql_query(&quote;UPDATE forumentries SET forumid = '$topictomove' WHERE topicid = '$topictomove2'&quote;);
		}
		echo &quote;&lt;p align=center&gt;&lt;B&gt;Topic has been moved.&lt;/B&gt;&lt;/p&gt;&quote;;
	}
}

// End administration

// Purify $_GET information
$forumid = mysql_real_escape_string(strip_tags($forumid));

// Select the forum name
$forumarray = mysql_fetch_assoc(mysql_query(&quote;SELECT topicname FROM forumtopics WHERE id = '$forumid'&quote;));

// Begin pagination for main page
$sql_text = (&quote;SELECT id, topicname, threadstatus, author FROM forumtopicmain WHERE forumid = '$forumid' AND type != 'sticky' ORDER BY lastreply DESC&quote;);
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 &lt;= 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 &gt; $num_pages) || ($page &lt; 0))
{
	die(&quote;You have specified an invalid page number&quote;);
}
$sql_text = $sql_text . &quote; LIMIT $page_start, 25&quote;; 
$query = mysql_query($sql_text); ?&gt;

&lt;a href=&quote;forums.php&quote;&gt;Show My Pro Forums&lt;/a&gt; &gt; &lt;a href=&quote;showforum.php?forumid=&lt;? echo $forumid; ?&gt;&quote;&gt;&lt;? echo $forumarray&#1111;'topicname']; ?&gt;&lt;/a&gt; &gt; &lt;a href=&quote;newforumtopic.php?forumid=&lt;? echo $forumid; ?&gt;&quote;&gt;&lt;img src=&quote;images/newtopic.gif&quote; alt=&quote;New Topic&quote; border=&quote;0&quote;&gt;&lt;/a&gt;
&lt;table width=&quote;100%&quote; cellspacing=&quote;0&quote; cellpadding=&quote;3&quote; style=&quote;border: solid 1px #000000&quote;&gt;
	&lt;tr&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; align=&quote;center&quote; colspan=&quote;5&quote; bgcolor=&quote;#CCCCCC&quote;&gt;&lt;B&gt;&lt;font size=&quote;2&quote;&gt;A Space For Your Thoughts&lt;/font&gt;&lt;/B&gt;
		&lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; align=&quote;center&quote; width=&quote;5%&quote; bgcolor=&quote;#CCCCCC&quote;&gt;&amp;nbsp;
		&lt;/td&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; align=&quote;center&quote; width=&quote;50%&quote; bgcolor=&quote;#CCCCCC&quote;&gt;&lt;B&gt;&lt;font size=&quote;2&quote;&gt;Topic&lt;/font&gt;&lt;/B&gt;
		&lt;/td&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; align=&quote;center&quote; width=&quote;10%&quote; bgcolor=&quote;#CCCCCC&quote;&gt;&lt;B&gt;&lt;font size=&quote;2&quote;&gt;Replies&lt;/font&gt;&lt;/B&gt;
		&lt;/td&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; align=&quote;center&quote; width=&quote;15%&quote; bgcolor=&quote;#CCCCCC&quote;&gt;&lt;B&gt;&lt;font size=&quote;2&quote;&gt;Author&lt;/font&gt;&lt;/B&gt;
		&lt;/td&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; align=&quote;center&quote; width=&quote;20%&quote; bgcolor=&quote;#CCCCCC&quote;&gt;&lt;B&gt;&lt;font size=&quote;2&quote;&gt;Last Post&lt;/font&gt;&lt;/B&gt;
		&lt;/td&gt;
	&lt;/tr&gt;
&lt;? 

// Show stickies first
if($page == &quote;1&quote;)
{
	$stickyquery = mysql_query(&quote;SELECT id, topicname, threadstatus, author FROM forumtopicmain WHERE forumid = '$forumid' AND type = 'sticky' ORDER BY lastreply DESC&quote;);
	while($stickyarray = mysql_fetch_assoc($stickyquery))
	{
		$stickyquery2 = mysql_query(&quote;SELECT id FROM forumentries WHERE topicid = '&quote;.$stickyarray&#1111;'id'].&quote;'&quote;);
		$stickyreplies = mysql_num_rows($stickyquery2) - 1;
		$stickylastpostarray = mysql_fetch_assoc(mysql_query(&quote;SELECT time, author FROM forumentries WHERE topicid = '&quote;.$stickyarray&#1111;'id'].&quote;' ORDER BY time2 DESC LIMIT 1&quote;)); ?&gt;
	&lt;tr&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; width=&quote;5%&quote; align=&quote;center&quote;&gt;&lt;? if($stickyarray&#1111;'threadstatus'] == &quote;open&quote;){ ?&gt;&lt;img src=&quote;images/thread_open.gif&quote;&gt;&lt;? } ELSE { ?&gt;&lt;img src=&quote;images/thread_locked.gif&quote;&gt; &lt;? } ?&gt;
		&lt;/td&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; width=&quote;50%&quote; align=&quote;left&quote;&gt;&lt;a href=&quote;showthread.php?threadid=&lt;? echo $stickyarray&#1111;'id']; ?&gt;&amp;page=1&quote;&gt;&lt;? echo &quote;STICKY: &quote;.stripslashes($stickyarray&#1111;'topicname']).&quote;&quote;; ?&gt;&lt;/a&gt;
		&lt;/td&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; width=&quote;10%&quote; align=&quote;center&quote;&gt;&lt;B&gt;&lt;font size=&quote;2&quote;&gt;&lt;? echo $stickyreplies; ?&gt;&lt;/B&gt;
		&lt;/td&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; width=&quote;15%&quote; align=&quote;center&quote;&gt;&lt;a href=&quote;showme.php?u=&lt;? echo $stickyarray&#1111;'author']; ?&gt;&quote;&gt;&lt;? echo $stickyarray&#1111;'author']; ?&gt;&lt;/a&gt;
		&lt;/td&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; width=&quote;20%&quote; align=&quote;left&quote;&gt;&lt;font size=&quote;2&quote;&gt;&lt;? echo $stickylastpostarray&#1111;'time']; ?&gt;&lt;/font&gt;&lt;BR&gt;&lt;font size=&quote;2&quote;&gt;by&lt;/font&gt; &lt;a href=&quote;showme.php?u=&lt;? echo $stickylastpostarray&#1111;'author']; ?&gt;&quote;&gt;&lt;? echo $stickylastpostarray&#1111;'author']; ?&gt;&lt;/a&gt;
		&lt;/td&gt;
	&lt;/tr&gt;
&lt;?
	}
}


// Show the non-stickied topics (most of them)
while($array = mysql_fetch_assoc($query))
{ 
	$query2 = mysql_query(&quote;SELECT id FROM forumentries WHERE topicid = '&quote;.$array&#1111;'id'].&quote;'&quote;);
	$replies = mysql_num_rows($query2) - 1;
	$lastpostarray = mysql_fetch_assoc(mysql_query(&quote;SELECT time, author FROM forumentries WHERE topicid = '&quote;.$array&#1111;'id'].&quote;' ORDER BY time2 DESC LIMIT 1&quote;));

	// Show the number of pages for each individual topic
	$sql_text2 = (&quote;SELECT id FROM forumentries WHERE topicid = '&quote;.$array&#1111;'id'].&quote;'&quote;);
	$query2 = mysql_query($sql_text2);
	$page_start2 = (25 * $page2) - 25; 
	$num_rows2 = mysql_num_rows($query2); 
	if ($num_rows2 &lt;= 25) { $num_pages2 = 1; } else if
	(($num_rows2 % 25) == 0) { $num_pages2 = ($num_rows2 / 25); } else {
	$num_pages2 = ($num_rows2 / 25) + 1; }
	$num_pages2 = (int) $num_pages2; 
	$sql_text2 = $sql_text2 . &quote; LIMIT $page_start2, 25&quote;; ?&gt;
	&lt;tr&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; width=&quote;5%&quote; align=&quote;center&quote;&gt;&lt;? if($array&#1111;'threadstatus'] == &quote;open&quote;){ ?&gt;&lt;img src=&quote;images/thread_open.gif&quote;&gt;&lt;? } ELSE { ?&gt;&lt;img src=&quote;images/thread_locked.gif&quote;&gt; &lt;? } ?&gt;
		&lt;/td&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; width=&quote;50%&quote; align=&quote;left&quote;&gt;&lt;a href=&quote;showthread.php?threadid=&lt;? echo $array&#1111;'id']; ?&gt;&amp;page=1&quote;&gt;&lt;? echo stripslashes($array&#1111;'topicname']); ?&gt;&lt;/a&gt;&lt;? if($num_pages2 &gt; 1){ echo &quote;&lt;BR&gt;&lt;font size=1&gt;Page: &lt;/font&gt;&quote;; for ($i = 1; $i &lt;= $num_pages2; $i++) {echo &quote;&lt;a href=\&quote;showthread.php?threadid=&quote;.$array&#1111;'id'].&quote;&amp;page=$i\&quote;&gt;&lt;font size=1&gt;$i&lt;/font&gt;&lt;/a&gt; &quote;; } } ?&gt;
		&lt;/td&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; width=&quote;10%&quote; align=&quote;center&quote;&gt;&lt;B&gt;&lt;font size=&quote;2&quote;&gt;&lt;? echo $replies; ?&gt;&lt;/B&gt;
		&lt;/td&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; width=&quote;15%&quote; align=&quote;center&quote;&gt;&lt;a href=&quote;showme.php?u=&lt;? echo $array&#1111;'author']; ?&gt;&quote;&gt;&lt;? echo $array&#1111;'author']; ?&gt;&lt;/a&gt;
		&lt;/td&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; width=&quote;20%&quote; align=&quote;left&quote;&gt;&lt;font size=&quote;2&quote;&gt;&lt;? echo $lastpostarray&#1111;'time']; ?&gt;&lt;/font&gt;&lt;BR&gt;&lt;font size=&quote;2&quote;&gt;by&lt;/font&gt; &lt;a href=&quote;showme.php?u=&lt;? echo $lastpostarray&#1111;'author']; ?&gt;&quote;&gt;&lt;? echo $lastpostarray&#1111;'author']; ?&gt;&lt;/a&gt;
		&lt;/td&gt;
	&lt;/tr&gt;&lt;?
} ?&gt;
&lt;/table&gt;
&lt;a href=&quote;forums.php&quote;&gt;Show My Pro Forums&lt;/a&gt; &gt; &lt;a href=&quote;showforum.php?forumid=&lt;? echo $forumid; ?&gt;&quote;&gt;&lt;? echo $forumarray&#1111;'topicname']; ?&gt;&lt;/a&gt; &gt; &lt;a href=&quote;newforumtopic.php?forumid=&lt;? echo $forumid; ?&gt;&quote;&gt;&lt;img src=&quote;images/newtopic.gif&quote; alt=&quote;New Topic&quote; border=&quote;0&quote;&gt;&lt;/a&gt;
&lt;p class=&quote;main&quote;&gt;&lt;center&gt;
&lt;?
// Show next 10 pages, previous 10 pages, etc.. for the number of pages in the forum
$limit = $page+10;
if($num_pages &gt;= $limit)
{
	if($page != 1)
	{
	$previouspage = $page - 1;
	$previousstart = $previouspage - 9;
		if($page == 2)
		{
			echo &quote;&lt;small&gt;&lt;&lt;&lt;/small&gt; &lt;a href=\&quote;$PHP_SELF?forumid=$forumid&amp;page=1\&quote;&gt;Page 1&lt;/a&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&quote;;
		} ELSE
		{
			if($previousstart &lt;= 0)
			{
				echo&quote;&lt;small&gt;&lt;&lt;&lt;/small&gt; &lt;a href=\&quote;$PHP_SELF?forumid=$forumid&amp;page=1\&quote;&gt;Pages 1 - $previouspage&lt;/a&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&quote;;
			} ELSE
			{
				echo &quote;&lt;small&gt;&lt;&lt;&lt;/small&gt; &lt;a href=\&quote;$PHP_SELF?forumid=$forumid&amp;page=$previousstart\&quote;&gt;Pages $previousstart - $previouspage&lt;/a&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&quote;;
			}
		}
	}
	for($i = $page; $i&lt;$limit; $i++)
	{
		echo &quote; &lt;a href=\&quote;$PHP_SELF?forumid=$forumid&amp;page=$i\&quote;&gt;$i&lt;/a&gt; &quote;;
	}
	$limit2 = $i+9;
	if($num_pages &lt;= $limit2)
	{
		echo &quote;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;a href=\&quote;$PHP_SELEF?forumid=$forumid&amp;page=$i\&quote;&gt;Pages $i - $num_pages&lt;/a&gt; &lt;small&gt;&gt;&gt;&lt;/small&gt;&quote;;
	} ELSE
	{
		echo &quote;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;a href=\&quote;$PHP_SELEF?forumid=$forumid&amp;page=$i\&quote;&gt;Pages $i - $limit2&lt;/a&gt; &lt;small&gt;&gt;&gt;&lt;/small&gt;&quote;;
	}
} ELSE
{
	for($i = $page; $i&lt;=$num_pages; $i++)
	{
		echo &quote; &lt;a href=\&quote;$PHP_SELF?forumid=$forumid&amp;page=$i\&quote;&gt;$i&lt;/a&gt; &quote;;
	}
}
?&gt;
&lt;/center&gt;&lt;/p&gt;
&lt;p align=&quote;left&quote; class=&quote;main&quote;&gt;&lt;img src=&quote;images/to_e.gif&quote;&gt; Thread Open&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;img src=&quote;images/tl_e.gif&quote;&gt; Thread Locked&lt;/font&gt;&lt;/p&gt;

&lt;?
// Start administration panel
$adminarray = array(&quote;scrotaye&quote;, &quote;artbalaoro&quote;, &quote;potato&quote;, &quote;magicflymonkey&quote;);
if(in_array($_COOKIE&#1111;'username'], $adminarray))
	{
?&gt;
&lt;table width=&quote;60%&quote; align=&quote;center&quote; style=&quote;border: solid 1px #000000&quote; cellspacing=&quote;0&quote; cellpading=&quote;3&quote;&gt;
	&lt;tr&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; align=&quote;center&quote; bgcolor=&quote;#CCCCCC&quote;&gt;&lt;B&gt;&lt;font size=&quote;2&quote;&gt;Administration Panel&lt;/font&gt;&lt;/B&gt;
		&lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
		&lt;td style=&quote;border: solid 1px #000000&quote; align=&quote;center&quote;&gt;
&lt;form action=&quote;showforum.php?forumid=&lt;? echo $forumid; ?&gt;&quote; method=&quote;post&quote;&gt;
&lt;input type=&quote;hidden&quote; name=&quote;action&quote; value=&quote;lockthread&quote;&gt;
&lt;p align=&quote;center&quote;&gt;&lt;B&gt;&lt;font size=&quote;2&quote;&gt;Lock Thread&lt;/font&gt;&lt;/B&gt;&lt;BR&gt;
&lt;select name=&quote;threadtolock&quote;&gt;
&lt;option selected&gt;Select&lt;/option&gt;&lt;?
$threadtolockquery = mysql_query(&quote;SELECT id, topicname FROM forumtopicmain WHERE forumid = '$forumid' ORDER BY lastreply DESC LIMIT 25&quote;);
while($threadtolockarray = mysql_fetch_assoc($threadtolockquery))
	{ ?&gt;
	&lt;option value=&quote;&lt;? echo $threadtolockarray&#1111;'id']; ?&gt;&quote;&gt;&lt;? echo stripslashes($threadtolockarray&#1111;'topicname']); ?&gt;&lt;/option&gt;&lt;?
	} ?&gt;
&lt;/select&gt;
&lt;BR&gt;
&lt;input type=&quote;submit&a

Posted: Sat Jul 16, 2005 10:01 pm
by nielsene
Nothing jumps out at me, have you tried adding some time stamps throughout the code to see where the time is being spent?

The most likely candidates, in my mind are the queries. Especially some of the nested queries inside the loops. You might be able to do better with a join to avoid the n+1 query pattern.

Posted: Sat Jul 16, 2005 10:52 pm
by s.dot
I viewed the page in mozilla.. it shows the page as it loads

and it would show a topic.. pause.. show a topic.. pause.. etc

So I'm guessing the loading time is looping through the topics.. which is the main part ;/

Posted: Sun Jul 17, 2005 12:03 am
by nielsene
So it sounds like round-tripping to your database is slow.

Is the database on the same machine as the web server? (Ie is there network delay in the queries?)

How many hows do you have in the relevant tables? If "many" do you have indexes or other tunings for those tables?

Can you try collapseing the queries to fewer queries: for instance:

Code: Select all

$sql_text = ("SELECT forumtopicmain.id, topicname, threadstatus, author, count(forumentries.id) 
FROM forumtopicmain JOIN forumentries ON (forumtopicmain.id=forumentries.topicid) 
WHERE forumid = '$forumid' AND type != 'sticky' 
GRUOP BY forumtopicmain.id, topicmain, threadstatus, author, lastreply 
ORDER BY lastreply DESC");
[snip]
    $lastpostarray = mysql_fetch_assoc(mysql_query("SELECT time, author FROM forumentries WHERE topicid = '".$array['id']."' ORDER BY time2 DESC LIMIT 1"));
This should let you get rid of two of the queries per topic. (Actually, why were you issueing the same query twice in a row?)

and similarly for the stickies.


The queries might need a little bit of tweaking... I'm a PostGreSQL guy, but I think they should be similar enough....

Its a good idea to remember that the database is almost always more efficient that anything you can do in PHP. Database are typically highly optimized code, written in C and compiled. Therefore the database will likely beat anything PHP does. Most database thrive on "large" queries. Simple selects, without joins or other "stuff", often have a rather large degree of "overhead". In many cases the combined query that I'm suggesting above will be faster than the sum of all the little queries in terms of pure database time, plus has only one "batch" of overhead, while the original version had 1+2n amounts of overhead. is slow.

Is the database on the same machine as the web server? (Ie is there network delay in the queries?)

How many hows do you have in the relevant tables? If "many" do you have indexes or other tunings for those tables?

Can you try collapseing the queries to fewer queries: for instance:

Code: Select all

$sql_text = ("SELECT forumtopicmain.id, topicname, threadstatus, author, count(forumentries.id) 
FROM forumtopicmain JOIN forumentries ON (forumtopicmain.id=forumentries.topicid) 
WHERE forumid = '$forumid' AND type != 'sticky' 
GRUOP BY forumtopicmain.id, topicmain, threadstatus, author, lastreply 
ORDER BY lastreply DESC");
[snip]
    $lastpostarray = mysql_fetch_assoc(mysql_query("SELECT time, author FROM forumentries WHERE topicid = '".$array['id']."' ORDER BY time2 DESC LIMIT 1"));
This should let you get rid of two of the queries per topic. (Actually, why were you issueing the same query twice in a row?)

and similarly for the stickies.


The queries might need a little bit of tweaking... I'm a PostGreSQL guy, but I think they should be similar enough....

Its a good idea to remember that the database is almost always more efficient that anything you can do in PHP. Database are typically highly optimized code, written in C and compiled. Therefore the database will likely beat anything PHP does. Most database thrive on "large" queries. Simple selects, without joins or other "stuff", often have a rather large degree of "overhead". In many cases the combined query that I'm su machine as the web server? (Ie is there network delay in the queries?)

How many hows do you have in the relevant tables? If "many" do you have indexes or other tunings for those tables?

Can you try collapseing the queries to fewer queries: for instance:

Code: Select all

$sql_text = ("SELECT forumtopicmain.id, topicname, threadstatus, author, count(forumentries.id) 
FROM forumtopicmain JOIN forumentries ON (forumtopicmain.id=forumentries.topicid) 
WHERE forumid = '$forumid' AND type != 'sticky' 
GRUOP BY forumtopicmain.id, topicmain, threadstatus, author, lastreply 
ORDER BY lastreply DESC");
[snip]
    $lastpostarray = mysql_fetch_assoc(mysql_query("SELECT time, author FROM forumentries WHERE topicid = '".$array['id']."' ORDER BY time2 DESC LIMIT 1"));
This should let you get rid of two of the queries per topic. (Actually, why were you issueing the same query twice in a row?)

and similarly for the stickies.


The queries might need a little bit of tweaking... I'm a PostGreSQL guy, but I think they should be similar enough....

Its a good idea to remember that the database is almost always more efficient that anything you can do in PHP. Database are typically highly optimized code, written in C and compiled. Therefore the database will likely beat anything PHP does. Most database thrive on "large" queries. Simple selects, without joins or other ay in the queries?)

How many hows do you have in the relevant tables? If "many" do you have indexes or other tunings for those tables?

Can you try collapseing the queries to fewer queries: for instance:

Code: Select all

$sql_text = ("SELECT forumtopicmain.id, topicname, threadstatus, author, count(forumentries.id) 
FROM forumtopicmain JOIN forumentries ON (forumtopicmain.id=forumentries.topicid) 
WHERE forumid = '$forumid' AND type != 'sticky' 
GRUOP BY forumtopicmain.id, topicmain, threadstatus, author, lastreply 
ORDER BY lastreply DESC");
[snip]
    $lastpostarray = mysql_fetch_assoc(mysql_query("SELECT time, author FROM forumentries WHERE topicid = '".$array['id']."' ORDER BY time2 DESC LIMIT 1"));
This should let you get rid of two of the queries per topic. (Actually, why were you issueing the same query twice in a row?)

and similarly for the stickies.


The queries might need a little bit of tweaking... I'm a PostGreSQL guy, but I think they should be similar enough....

Its a good idea to remember that the database is almost always more efficient that anything you can do in PHP. Database are typically highly optimized code, written in C and compiled. Therefore the database will likely beat anything PHP does. Most database thrive on "large" queries. Simple selects, without joins or other "stuff", often have a rather large degree ois there network delay in the queries?)

How many hows do you have in the relevant tables? If "many" do you have indexes or other tunings for those tables?

Can you try collapseing the queries to fewer queries: for instance:

Code: Select all

$sql_text = ("SELECT forumtopicmain.id, topicname, threadstatus, author, count(forumentries.id) 
FROM forumtopicmain JOIN forumentries ON (forumtopicmain.id=forumentries.topicid) 
WHERE forumid = '$forumid' AND type != 'sticky' 
GRUOP BY forumtopicmain.id, topicmain, threadstatus, author, lastreply 
ORDER BY lastreply DESC");
[snip]
    $lastpostarray = mysql_fetch_assoc(mysql_query("SELECT time, author FROM forumentries WHERE topicid = '".$array['id']."' ORDER BY time2 DESC LIMIT 1"));
This should let you get rid of two of the queries per topic. (Actually, why were you issueing the same query twice in a row?)

and similarly for the stickies.


The queries might need a little bit of tweaking... I'm a PostGreSQL guy, but I round-tripping to your database is slow.

Is the database on the same machine as the web server? (Ie is there network delay in the queries?)

How many hows do you have in the relevant tables? If "many" do you have indexes or other tunings for those tables?

Can you try collapseing the queries to fewer queries: for instance:

Code: Select all

$sql_text = ("SELECT forumtopicmain.id, topicname, threadstatus, author, count(forumentries.id) 
FROM forumtopicmain JOIN forumentries ON (forumtopicmain.id=forumentries.topicid) 
WHERE forumid = '$forumid' AND type != 'sticky' 
GRUOP BY forumtopicmain.id, topicmain, threadstatus, author, lastreply 
ORDER BY lastreply DESC");
[snip]
    $lastpostarray = mysql_fetch_assoc(mysql_query("SELECT time, author FROM forumentries WHERE topicid = '".$array['id']."' ORDER BY time2 DESC LIMIT 1"));
This should let you get rid of two of the queries per topic. (Actually, why were you issueing the same query twice in a row?)

and similarly for the stickies.


The queries might need a little bit of tweaking... I'm a PostGreSQL guy, but I think they should be similar enough....

Its a good idea to remember that the database is almost always more efficient that anything you can do in PHP. Database are typically highly optimized code, written in C and compiled. Therefore the database will likely beat anything PHP does. Most database thrive on "large" queries. Simple selects, without joins or other "stuff", often have a rather large degree of "overhead". In many cases the combined query that I'm suggesting above will be faster than the sum of all the little queries in terms of pure database time, plus has only one "batch" of overheround-tripping to your database is slow.

Is the database on the same machine as the web server? (Ie is there network delay in the queries?)

How many hows do you have in the relevant tables? If "many" do you have indexes or other tunings for those tables?

Can you try collapseing the queries to fewer queries: for instance:

Code: Select all

$sql_text = ("SELECT forumtopicmain.id, topicname, threadstatus, author, count(forumentries.id) 
FROM forumtopicmain JOIN forumentries ON (forumtopicmain.id=forumentries.topicid) 
WHERE forumid = '$forumid' AND type != 'sticky' 
GRUOP BY forumtopicmain.id, topicmain, threadstatus, author, lastreply 
ORDER BY lastreply DESC");
[snip]
    $lastpostarray = mysql_fetch_assoc(mysql_query("SELECT time, author FROM forumentries WHERE topicid = '".$array['id']."' ORDER BY time2 DESC LIMIT 1"));
This should let you get rid of two of the queries per topic. (Actually, why were you issueing the same query twice in a row?)

and similarly for the stickies.


The queries might need a little bit of tweaking... I'm a PostGreSQL guy, but I think they should be similar enough....

Its a good idea to remember that the database is almost always more efficient that anything you can do in PHP. Database are typically highly optimized code, written in C and compiled. Therefore the database will likely beat anything PHP does. Most database thrive on "large"Y forumtopicmain.id, topicmain, threadstatus, author, lastreply
ORDER BY lastreply DESC");
[snip]
$lastpostarray = mysql_fetch_assoc(mysql_query("SELECT time, author FROM forumentries WHERE topicid = '".$array['id']."' ORDER BY time2 DESC LIMIT 1"));


This should let you get rid of two of the queries per topic. (Actually, why were you issueing the same query twice in a row?)

and similarly for the stickies.


The queries might need a little bit of tweaking... I'm a PostGreSQL guy, but I think they should be similar enough....

Its a good idea to remember that the database is almost always more efficient that anything you can do in PHP. Database are typically highly optimized code, written in C and compiled. Therefore the database will likely beat anything PHP does. Most database thrive on "large" queries. Simple selects, without joins or other "stuff", often have a rather large degree of "overhead". In many cases the combined query that I'm suggesting above will be faster than the sum of all the little queries in terms of pure database time, plus has only one "batch" of overhead, while the original version had 1+2n amounts of overhead.;quote;.$array['id']."' ORDER BY time2 DESC LIMIT 1"));


This should let you get rid of two of the queries per topic. (Actually, why were you issueing the same query twice in a row?)

and similarly for the stickies.


The queries might need a little bit of tweaking... I'm a PostGreSQL guy, but I think they should be similar enough....

Its a good idea to remember that the database is almost alwe machine as the web server? (Ie is there network delay in the queries?)

How many hows do you have in the relevant tables? If "many" do you have indexes or other tunings for those tables?

Can you try collapseing the queries to fewer queries: for instance:

Code: Select all

$sql_text = ("SELECT forumtopicmain.id, topicname, threadstatus, author, count(forumentries.id) 
FROM forumtopicmain JOIN forumentries ON (forumtopicmain.id=forumentries.topicid) 
WHERE forumid = '$forumid' AND type != 'sticky' 
GRUOP BY forumtopicmain.id, topicmain, threadstatus, author, lastreply 
ORDER BY lastreply DESC");
[snip]
    $lastpostarray = mysql_fetch_assoc(mysql_query("SELECT time, author FROM forumentries WHERE topicid = '".$array['id']."' ORDER BY time2 DESC LIMIT 1"));
This should let you get rid of two of the queries per topic. (Actually, why were you issueing the same query twice in a row?)

and similarly for the stickies.


The queries might need a little bit of tweaking... I'mrver? (Ie is there network delay in the queries?)

How many hows do you have in the relevant tables? If "many" do you have indexes or other tunings for those tables?

Can you try collapseing the queries to fewer queries: for instance:

Code: Select all

$sql_text = ("SELECT forumtopicmain.id, topicname, threadstatus, author, count(forumentries.id) 
FROM forumtopicmain JOIN forumentries ON (forumtopicmain.id=forumentries.topicid) 
WHERE forumid = '$forumid' AND type != 'sticky' 
GRUOP BY forumtopicmain.id, topicmain, threadstatus, author, lastreply 
ORDER BY lastreply DESC");
[snip]
    $lastpostarray = mysql_fetch_assoc(mysql_query("SELECT time, author FROM forumentries WHERE topicid = '".$array['id']."' ORDER BY time2 DESC LIMIT 1"));
This should let you get rid of two of the queries per topic. (Actually, why were you issueing the same query twice in a row?)

and similarly for the stickies.


The queries might need a little bit of tweaking... I'm a PostGreSQL guy, but I think they should be similar enough....

Its a good idea to remember that the database is almost always more efficient that anything you can do in PHP. Database are typically highly optimized code, written in C and compiled. Theref.

Is the database on the same machine as the web server? (Ie is there network delay in the queries?)

How many hows do you have in the relevant tables? If "many" do you have indexes or other tunings for those tables?

Can you try collapseing the queries to fewer queries: for instance:

Code: Select all

$sql_text = ("SELECT forumtopicmain.id, topicname, threadstatus, author, count(forumentries.id) 
FROM forumtopicmain JOIN forumentries ON (forumtopicmain.id=forumentries.topicid) 
WHERE forumid = '$forumid' AND type != 'sticky' 
GRUOP BY forumtopicmain.id, topicmain, threadstatus, author, lastreply 
ORDER BY lastreply DESC");
[snip]
    $lastpostarray = mysql_fetch_assoc(mysql_query("SELECT time, author FROM forumentries WHERE topicid = '".$array['id']."' ORDER BY time2 DESC LIMIT 1"));
This should let you get rid of two of the queries per topic. (Actually, why were you issueing the same query twice in a row?)

and similarly for the stickies.

bles? If "many" do you have indexes or other tunings for those tables?

Can you try collapseing the queries to fewer queries: for instance:

Code: Select all

$sql_text = ("SELECT forumtopicmain.id, topicname, threadstatus, author, count(forumentries.id) 
FROM forumtopicmain JOIN forumentries ON (forumtopicmain.id=forumentries.topicid) 
WHERE forumid = '$forumid' AND type != 'sticky' 
GRUOP BY forumtopicmain.id, topicmain, threadstatus, author, lastreply 
ORDER BY lastreply DESC");
[snip]
    $lastpostarray = mysql_fetch_assoc(mysql_query("SELECT time, author FROM forumentries WHERE topicid = '".$array['id']."' ORDER BY time2 DESC LIMIT 1"));
This should let you get rid of two of the queries per topic. (Actually, why were you issueing the same query twice in a row?)

and similarly for the stickies.


The queries might need a little bit of tweaking... I'm a PostGreSQL guy, but I think they should be similar enough....

Its a good idea to remember that the database is almost always more efficient that anything you can do in PHP. Database are typically highly optimized code, written in C and compiled. Therefore the database will likely beat anything PHP does. Most database thrive on "large" queries. Simple selects, without joins or other "stuff", often have a rather large degree of "overhead". In many cases the combined query that I'm suggesting above will be faster than the sum of all the little queries in terms of pure database time, plus has only o
$sql_text = ("SELECT forumtopicmain.id, topicname, threadstatus, author, count(forumentries.id)
FROM forumtopicmain JOIN forumentries ON (forumtopicmain.id=forumentries.topicid)
WHERE forumid = '$forumid' AND type != 'sticky'
GRUOP BY forumtopicmain.id, topicmain, threadstatus, author, lastreply
ORDER BY lastreply DESC");
[snip]
$lastpostarray = mysql_fetch_assoc(mysql_query("SELECT time, author FROM forumentries WHERE topicid = '".$array['id']."' ORDER BY time2 DESC LIMIT 1"));


This should let you get rid of two of the queries per topic. (Actually, why were you issueing the same query twice in a row?)

and similarly for the stickies.


The queries might need a little bit of tweaking... I'm a PostGreSQL guy, but I think they should be similar enough....

Its a good idea to remember that the database is almost always more efficient that anything you can do in PHP. Database are typically highly optimized code, written in C and compiled. Therefore the database will likely beat anything PHP does. Most database thrive on "large" queries. Simple selects, without joins or other "stuff", often have a rather large degree of "overhead". In many cases the combined query that I'm suggesting above will be faster than the sum of all the little queries in terms of pure database time, plus has only one "batch" of overhead, while the original version had 1+2n amounts of overhead.

Posted: Sun Jul 17, 2005 7:09 am
by bokehman
Are you saying the page doesn't load until processing is finished? If so this is an issue with output buffering. At least if the page starts loading the client feels something is happening. On my site if I know something will take a while to process I flush the previous info to the browser. If you want to see what I mean have a look at this. Anyway I do that like this:
ini_set('output_buffering', 'Off');
ini_set('implicit_flush', '1');
and then put
flush;
before anything that is going to consume time. GZIPed also have the same problem because they are buffered and not displayed until after the last packet arrives.

Secondly to help in the matter of timing the various parts of your pages I am posting the following function:

Code: Select all

<?php
function elapsed_time_in_milliseconds($start, $end){
	$start = explode(' ', $start);
	$start = $start[0] + $start[1];
	$end = explode(' ', $end);
	$end = $end[0] + $end[1];
	return (round(($end - $start) * 1000));
}
	
	
	
$start = microtime();

// Put here code or function you wish to time

$end = microtime();

print(elapsed_time_in_milliseconds($start, $end) . ' milliseconds');
?>
sing is finished? If so this is an issue with output buffering. At least if the page starts loading the client feels something is happening. On my site if I know something will take a while to process I flush the previous info to the browser. If you want to see what I mean have a look at this. Anyway I do that like this:
ini_set('output_buffering', 'Off');
ini_set('implicit_flush', '1');
and then put
flush;
before anything that is going to consume time. GZIPed also have the same problem because they are buffered and not displayed until after the last packet arrives.

Secondly to help in the matter of timing the various parts of your pages I am posting the following function:

Code: Select all

&lt;?php
function elapsed_time_in_milliseconds($start, $end){
	$start = explode(' ', $start);
	$start = $start&#1111;0] + $start&#1111;1];
	$end = explode(' ', $end);
	$end = $end&#1111;0] + $end&#1111;1];
	return (round(($end - $start) * 1000));
}
	
	
	
$st with output buffering. At least if the page starts loading the client feels something is happening. On my site if I know something will take a while to process I flush the previous info to the browser. [url=http://myhomewebserver.co.uk/dns_test.php?domain=13.41.37.80.in-addr.arpa&type=PTR]If you want to see what I mean have a look at this.[/url] Anyway I do that like this:
ini_set('output_buffering', 'Off');
ini_set('implicit_flush', '1');
and then put 
flush; 
before anything that is going to consume time. GZIPed also have the same problem because they are buffered and not displayed until after the last packet arrives.

Secondly to help in the matter of timing the various parts of your pages I am posting the following function:

Code: Select all

&lt;?php
function elapsed_time_in_milliseconds($start, $end){
	$start = explode(' ', $start);
	$start = $start&#1111;0] + $start&#1111;1];
	$end = explode(' ', $enoading the client feels something is happening. On my site if I know something will take a while to process I flush the previous info to the browser. [url=http://myhomewebserver.co.uk/dns_test.php?domain=13.41.37.80.in-addr.arpa&type=PTR]If you want to see what I mean have a look at this.[/url] Anyway I do that like this:
ini_set('output_buffering', 'Off');
ini_set('implicit_flush', '1');
and then put 
flush; 
before anything that is going to consume time. GZIPed also have the same problem because they are buffered and not displayed until after the last packet arrives.

Secondly to help in the matter of timing the various parts of your pages I am posting the following function:

Code: Select all

&lt;?php
function elapsed_time_in_milliseconds($start, $end){
	$start = explode(' ', $start);
	$start = $start&#1111;0] + $start&#1111;1];
	$end = explode(' ', $end);
	$end = $end&#1111;0] + $end&#1111;1];if the page starts loading the client feels something is happening. On my site if I know something will take a while to process I flush the previous info to the browser. [url=http://myhomewebserver.co.uk/dns_test.php?domain=13.41.37.80.in-addr.arpa&type=PTR]If you want to see what I mean have a look at this.[/url] Anyway I do that like this:
ini_set('output_buffering', 'Off');
ini_set('implicit_flush', '1');
and then put 
flush; 
before anything that is going to consume time. GZIPed also have the same problem because they are buffered and not di page doesn't load until processing is finished? If so this is an issue with output buffering. At least if the page starts loading the client feels something is happening. On my site if I know something will take a while to process I flush the previous info to the browser. [url=http://myhomewebserver.co.uk/dns_test.php?domain=13.41.37.80.in-addr.arpa&type=PTR]If you want to see what I mean have a look at this.[/url] Anyway I do that like this:
ini_set('output_buffering', 'Off');
ini_set('implicit_flush', '1');
and then put 
flush; 
before anything that is going to consume time. GZIPed also have the same problem because they are buffered and not displayed until after the last packet arrives.

Secondly to help in the matter of timing the various parts of your pages I am posting the following function:

Code: Select all

&lt;?php
function elapsed_time_in_milliseconds($start, $end){
	$start = explode(' ', $start);
	$start = $start&#1111;0] + $start&#1111;1];
	$end = explode(' ', $end);
	$end = $end&#1111;0] + $end&#1111;1];
	return (round(($end - $start) * 1000));
}
	
	
	
$start = microtime();

// Put here code or function you wish to time

$end = microtime();

print(elapsed_time_in_milliseconds($start, page doesn't load until processing is finished? If so this is an issue with output buffering. At least if the page starts loading the client feels something is happening. On my site if I know something will take a while to process I flush the previous info to the browser. [url=http://myhomewebserver.co.uk/dns_test.php?domain=13.41.37.80.in-addr.arpa&type=PTR]If you want to see what I mean have a look at this.[/url] Anyway I do that like this:
ini_set('output_buffering', 'Off');
ini_set('implicit_flush', '1');
and then put 
flush; 
before anything that is going to consume time. GZIPed also have the same problem because they are buffered and not displayed until after the last packet arrives.

Secondly to help in the matter of timing the various parts of your pages I am posting the following function:

Code: Select all

<?php
function elapsed_time_in_milliseconds($start, $end){
	$start = explode(' ', $start);
	$start = $start[0] + $start[1];
	$end = explode(' ', $end);
	$end = $end[0] + $end[1];
	return (round(($end - $start) * 1000));
}
	
	
	
$start = microtime();

// Put here code or function you wish to time

$end = microtime();

print(elapsed_time_in_milliseconds($start, $end) . ' milliseconds');
?>
lso have the same problem because they are buffered and not displayed until after the last packet arrives.

Secondly to help in the matter of timing the various parts of your pages I am posting the following function:

Code: Select all

<?php
function elapsed_time_in_milliseconds($start, $end){
	$start = explode(' ', $start);
	$start = $start[0] + $start[1];
	$end = explode(' ', $end);
	$end = $end[0] + $end[1];
	return (round(($end - $start) * 1000));
}
	
	
	
$start = microtime();

// Put here code or function you wish to time

$end = microtime();

print(elapsed_time_in_milliseconds($start, $end) . ' milliseconds');
?>
<?php
function elapsed_time_in_milliseconds($start, $end){
$start = explode(' ', $start);
$start = $start[0] + $start[1];
$end = explode(' ', $end);
$end = $end[0] + $end[1];
return (round(($end - $start) * 1000));
}



$start = microtime();

// Put here code or function you wish to time

$end = microtime();

print(elapsed_time_in_milliseconds($start, $end) . ' milliseconds');
?>

Posted: Sun Jul 17, 2005 7:20 am
by Chris Corbyn
bokehman wrote:Are you saying the page doesn't load until processing is finished? If so this is an issue with output buffering.
Based on this description I'd guess not...
scrotaye wrote:I viewed the page in mozilla.. it shows the page as it loads

and it would show a topic.. pause.. show a topic.. pause.. etc

So I'm guessing the loading time is looping through the topics.. which is the main part ;/
It certainly does sound like it's something to do with the interface between MySQL and the PHP script as ~nielsene mentions (different servers?).

If the database is running on the same server is it being over utilised? - although it sounds excessive to say 10 seconds if that's the case.

Echoing timestamps throughout the code can't hurt... even better, microtime() displaying the time it took progress-wise to get to each step in seconds/milliseconds. Note: Echo a desription of what it's doing too so you can work out quicker where you are in a loop etc - this is good practise for optimizing code too.

If it does seem to lag at the points where it has to query the database then I'd be looking away from PHP and at MySQL (or the interface to it) itself. From your description of the problem it sounds clear where the slow points are though.