Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   This topic is locked: you cannot edit posts or make replies.    Ravens PHP Scripts And Web Hosting Forum Index -> For Hire
Author Message
unmgroup
New Member
New Member



Joined: Jun 04, 2006
Posts: 14

PostPosted: Sun Oct 08, 2006 10:20 pm Reply with quote

Hi,

I recently decided to setup a remote dedicated database server (on the same network as my dedicated webserver) to handle the increased popularity of my nuke site. However, this block is causing page load times of 17 seconds. Which leads me to believe it's not optimized. Whenever I remove this block from the front page, the site loads in 1 second. All other portions of the site load in under a second as well. So could somebody please optimize this code, or tell me where I can get a more up-to-date version of this center forum block??

The code is here:

Code:
<?php


/************************************************************************************/
/*                                                                                  */
/* CENTER BLOCK: block-phpBB_Forums.php                                             */
/* For PHP-Nuke 6.5                                                                 */
/* v1.5  06-04-2003                                                                 */
/*                                                                                  */
/* by: Maty Scripts (webmaster@matyscripts.com)                                     */
/* http://www.matyscripts.com                                                       */
/*                                                                                  */
/* This program is free software. You can redistribute it and/or modify             */
/* it under the terms of the GNU General Public License as published by             */
/* the Free Software Foundation; either version 2 of the License.                   */
/*                                                                                  */
/************************************************************************************/


if( eregi( "block-phpBB_Forums.php", $_SERVER['PHP_SELF'])) {
   Header("Location: index.php");
   die();
}

// include the Cache-Lite package
require_once("includes/Cache_Lite/Lite.php");

// set some variables
$options = array(
  "cacheDir" => "C:/Cache/",
  "lifeTime" => 10
);

// create a Cache_Lite object
$objCache = new Cache_Lite($options);

// test if there exists a valid cache,
// the ID will be the basename of the block
$fileid = basename($blockfile,".php");
if ($content = $objCache->get($fileid)) {
 }
else
{
  // do the block's work here...

global $prefix, $user_prefix, $db, $sitename, $bgcolor1, $bgcolor2;


/**********************************/
/*                                */
/* Configuration parameters       */
/*                                */
/**********************************/
// When set to 1 then Forums permissions which View and/or Read are NOT set to 'ALL' will NOT be displayed in the center block
$HideViewReadOnly = 0;
// Show only 5 last new topics
$Last_New_Topics  = 75;                           
// Icon that is displayed in Center Block in front of Topic
$IconPath         = "modules/Forums/templates/subSilver/images/icon_mini_message.gif";

/**********************************/
/*                                */
/* Don't Edit Below !             */
/*                                */
/**********************************/
$border           = 0;
$cellspacing      = 0;
$cellstyle        = "style=\"border-left-width: 1; border-right-width: 1; border-top-width: 1; border-bottom-style: solid; border-bottom-width: 1\"";

/* Total Amount of Topics */
$result = $db->sql_query( "SELECT * FROM ".$prefix."_bbtopics" );
$Amount_Of_Topics = $db->sql_numrows( $result );

/* Total Amount of Posts */
$result = $db->sql_query( "SELECT * FROM ".$prefix."_bbposts" );
$Amount_Of_Posts = $db->sql_numrows( $result );

/* Total Amount of Topic Views */
$Amount_Of_Topic_Views = 1;
$result = $db->sql_query( "SELECT topic_views FROM ".$prefix."_bbtopics" );
while( list( $topic_views ) = $db->sql_fetchrow( $result ) )
{
   $Amount_Of_Topic_Views = $Amount_Of_Topic_Views + $topic_views;
}

/* Total Amount of Topic Replies */
$Amount_Of_Topic_Replies = 1;
$result = $db->sql_query( "SELECT topic_replies FROM ".$prefix."_bbtopics" );
while( list( $topic_replies ) = $db->sql_fetchrow( $result ) )
{
   $Amount_Of_Topic_Replies = $Amount_Of_Topic_Replies + $topic_replies;
}

/* Total Amount of Members */
$result = $db->sql_query( "SELECT * FROM ".$user_prefix."_users" );
$Amount_Of_Members = $db->sql_numrows( $result ) - 1;
/* Last X New Topics */
$Count_Topics = 0;
$Topic_Buffer="";
$content  =  "<center><a href=\"/modules.php?name=Forums\"><img src=\"images/boards.gif\" border=\"0\"></a></center>";
$content  .=  "<center><b>Below is just a snap shot of our popular Message Boards:</b> <br><br>To view all topics, please click the icon above to enter the full<br> message board. Once inside, you can see all topics that have been recently<br> posted. The list below is generated automatically by the most recent posts.</center>";
$content  .=  "<br>";
$content  .=  "<br>";
$content  .=  "<center><font color=006699><b><big><big>Over 42,195+ Posts!</big></big></center></font>";
$content  .=  "<br>";
$content  .=  "<center><font color=gray><b>Some Topics Can Only Be Viewed By Members Logged In.</center></font>";
$content .= "<table><table><tr><td><table width=\"550\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td bgcolor=\"#CAC8C8\"><table width=\"100%\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" ><tr> ";
$content .= "<th height=\"20\" colspan=\"2\" align=\"center\" nowrap background=\"images/cellpic69.gif\" class=\"thcornerl\"><font color=\"#FFFFFF\"><strong>Topics</strong></font></th>";
$content .= "   <th width=\"50\" align=\"center\" nowrap background=\"images/cellpic69.gif\" class=\"thtop\"><font color=\"#FFFFFF\"><strong>&nbsp;Replies&nbsp;</strong></font></th>";
$content .= "    <th width=\"75\" align=\"center\" nowrap background=\"images/cellpic69.gif\" class=\"thtop\"><font color=\"#FFFFFF\"><strong>&nbsp;Author&nbsp;</strong></font></th>";
$content .= "  <th width=\"50\" align=\"center\" nowrap background=\"images/cellpic69.gif\" class=\"thtop\"><font color=\"#FFFFFF\"><strong>&nbsp;Views&nbsp;</strong></font></th>";
$content .= "  <th align=\"center\" nowrap background=\"/images/cellpic69.gif\" class=\"thcornerr\"><font color=\"#FFFFFF\"><strong>&nbsp;Last Post&nbsp;</strong></font></th>";
$content .= "   </tr>   ";

$result1 = $db->sql_query( "SELECT topic_id, forum_id, topic_last_post_id, topic_title, topic_poster, topic_views, topic_replies, topic_moved_id FROM ".$prefix."_bbtopics ORDER BY topic_last_post_id DESC" );
while( list( $topic_id, $forum_id, $topic_last_post_id, $topic_title, $topic_poster, $topic_views, $topic_replies, $topic_moved_id ) = sql_fetch_row( $result1, $dbi ) )
{
   $skip_display = 0;
   if( $HideViewReadOnly == 1 )
   {
      $result5 = $db->sql_query( "SELECT auth_view, auth_read FROM ".$prefix."_bbforums where forum_id = '$forum_id'" );
      list( $auth_view, $auth_read ) = $db->sql_fetchrow( $result5 );
      if( ( $auth_view != 0 ) or ( $auth_read != 0 ) ) { $skip_display = 1; }
   }
   
   if( $topic_moved_id != 0 )
   {
     // Shadow Topic !!
      $skip_display = 0;
   }
   
   if( $skip_display ==0 )
   {
     $Count_Topics += 1;
      $result2 = $db->sql_query( "SELECT topic_id, poster_id, FROM_UNIXTIME( post_time,'%b %d, %Y at %T') as post_time FROM ".$prefix."_bbposts where post_id = '$topic_last_post_id'" );
      list( $topic_id, $poster_id, $post_time ) = $db->sql_fetchrow( $result2 );

      $result3 = $db->sql_query( "SELECT username, user_id FROM ".$user_prefix."_users where user_id='$poster_id'" );
      list( $uname, $uid ) = $db->sql_fetchrow( $result3 );
      $LastPoster = "<A HREF=\"profile-.html$uid\"STYLE=\"text-decoration: none\"> $uname </a>";
     
      $result4 = $db->sql_query( "SELECT username, user_id FROM ".$user_prefix."_users where user_id='$topic_poster'" );
      list( $uname, $uid ) = $db->sql_fetchrow( $result4 );
      $OrigPoster = "<A HREF=\"profile-.html$uid\"STYLE=\"text-decoration: none\"> $uname </a>";
   
      $TopicImage = "<img src=\"$IconPath\" border=\"0\" alt=\"\">";
      $TopicTitleShow = "<a href=\"forums.html?amp;file=viewtopic&amp;p=$topic_last_post_id#$topic_last_post_id\"STYLE=\"text-decoration: none\">$topic_title</a>";


$content .= "<tr><td align=\"center\" height=\"30\" width=\"30\" nowrap bgcolor=\"#F4F6FB\" class=\"row1\"><img src=\"images/envelope691.gif\" border=\"0\" /></td>";
$content .= "<td width=\"100%\" bgcolor=\"#F4F6FB\" class=\"row1\">&nbsp;$TopicTitleShow</td>";
$content .= "<td align=\"center\" bgcolor=\"#F4F6FB\" class=\"row2\">$topic_replies</td>";
$content .= "<td align=\"center\" bgcolor=\"#F4F6FB\" class=\"row3\">$OrigPoster</td>";
$content .= "<td align=\"center\" bgcolor=\"#F4F6FB\" class=\"row2\">$topic_views</td>";
$content .= "<td width=\"100%\" align=\"center\" nowrap bgcolor=\"#F4F6FB\" class=\"row3\"><font size=\"-2\"><i>$post_time</i></font><BR>$LastPoster&nbsp;<a href=\"forums.html?amp;file=viewtopic&amp;p=$topic_last_post_id#$topic_last_post_id\"STYLE=\"text-decoration: none\"><img src=\"modules/Forums/templates/subSilver/images/icon_newest_reply.gif\" border=\"0\" alt=\"Latest Post\"></a></td></tr>   ";

   }
   
   if( $Last_New_Topics == $Count_Topics ) { break 1; }
   
}
$content .= "   <tr> <td bgcolor=\"#F4F6FB\" height=\"15\" colspan=\"6\" align=\"center\" class=\"cat\" background=\"images/cellpic3.gif\">&nbsp;</td>";
$content .= "  </tr>";
$content .= "</table>";
$content .="  </td>      </tr></table></table>";
$content  .=  "<br>";
$content  .=  "<center><a href=\"/modules.php?name=Forums\"><img src=\"images/enter.png\" border=\"0\"></a></center>";
$content  .=  "<br>";
$content .= "<center><b><font color=gray><u>Please Note</u>: The message boards are not moderated, or controlled by the staff!</font></center></b>";
$content  .=  "<br>";
$content  .=  "<br>";

// ...and save it in the cache for future use
  $objCache->save($content, $fileid);
}
?>


Please E-Mail me at: PlayBoy4u2c@aol.com , ICQ Me: 282-055-087, IM me on AOL: PlayBoy4u2c , Yahoo: HollaMayne . I need this done ASAP! And I will pay TOP DOLLAR![/quote]
 
View user's profile Send private message
montego
Site Admin



Joined: Aug 29, 2004
Posts: 9457
Location: Arizona

PostPosted: Mon Oct 09, 2006 8:33 pm Reply with quote

I have moved this where it will get the appropriate attention.

Well, sorry to ask the obvious, but are you really using CacheLite? If so, and if it is set up properly, I just cannot see why this would be slow, except when it is first caching/re-caching it. It has been awhile since I've set this up, but are you really wanting to re-cache every 10 seconds? Do your forums really change that frequently?

Have you asked MatyScripts about it?

_________________
Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
unmgroup







PostPosted: Wed Oct 11, 2006 3:45 am Reply with quote

montego wrote:
I have moved this where it will get the appropriate attention.

Well, sorry to ask the obvious, but are you really using CacheLite? If so, and if it is set up properly, I just cannot see why this would be slow, except when it is first caching/re-caching it. It has been awhile since I've set this up, but are you really wanting to re-cache every 10 seconds? Do your forums really change that frequently?

Have you asked MatyScripts about it?


Yes I am really using CacheLite, and my forums are quite popular. I have cachelite caching most of the blocks on my site, and it works without any problems. I tried to go onto Matyscripts website, but it said it was offline. If I set it to re-cache every 60 seconds the load time drops dramatically.
 
montego







PostPosted: Wed Oct 11, 2006 7:04 am Reply with quote

Ok. Just needed to ask. Sorry, but I don't have time for side jobs, but maybe someone else here will pick this up.
 
technocrat
Life Cycles Becoming CPU Cycles



Joined: Jul 07, 2005
Posts: 511

PostPosted: Wed Oct 11, 2006 8:06 am Reply with quote

How many posts do you think you get per day? If it is only a few then you can cache each topic and then get all the previous topics back from the cache.

I can optimize it some for you, but I am not sure how many seconds it will cut off.

_________________
Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! / Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message
montego







PostPosted: Wed Oct 11, 2006 8:12 pm Reply with quote

I was also wondering if some clever joins would be much better than nested selects... I always prefer making the DB do most of the "work" as it is usually optimized for such.
 
technocrat







PostPosted: Thu Oct 12, 2006 9:31 am Reply with quote

I would only save you a few cycles, and maybe 1/2 a second.
 
evaders99
Former Moderator in Good Standing



Joined: Apr 30, 2004
Posts: 3221

PostPosted: Thu Oct 12, 2006 10:55 am Reply with quote

If its not doing a lot of chugging on the remote database server, then perhaps it is trying to transfer a lot of data between the database and your webserver.

_________________
- Only registered users can see links on this board! Get registered or login! -

Need help? Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
Display posts from previous:       
Post new topic   This topic is locked: you cannot edit posts or make replies.    Ravens PHP Scripts And Web Hosting Forum Index -> For Hire

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©