PHP Web Host - Quality Web Hosting For All PHP Applications Just Great Software
  Login or Register
 • Home • Downloads • Your Account • Forums • 

View next topic
View previous topic


Google
 
Web RavenPHPScripts (This Site)
Post new topic   Reply to topic
Author Message
dean
Worker
Worker


Joined: Apr 14, 2004
Posts: 193

PostPosted: Fri Jul 22, 2005 1:23 pm Reply with quote Back to top

Yesterday I finally figured out how to use cache lite and also found a spot where not to, ie the user info block. I found it impossible to log in or out with that block cached. I thought that caching the block would really speed up the site because of all of the calls made to the database.

Is there any reason why block modules cannot be cached?

Also, one block in particular delivered a tstring error when the caching script was added to it. Is it possible that some blocks cannot be cached or is this a block that needs some modification to work? I'm speaking specifically about a block at my site at
Only registered users can see links on this board!
Get registered or login to the forums!
, lower left that displays a list of the last advertisements placed in the database (zclassified module).
View user's profile Send private message
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 15055
Location: Kansas

PostPosted: Fri Jul 22, 2005 3:42 pm Reply with quote Back to top

Blocks are the only thing that you will want to cahce, due to the way nuke builds blocks vs. modules. Modules can also be cached, but they can take alot of rewriting to do so. The rule of thumb is that you want to cache blocks that you can estimate the refresh time and especially those blocks that take time to build. So, since your userinfo block is mostly constantly changing, you would not want to cache it. Although you could remove the Login piece and use a more singular, stand-alone login block. Then, you would alleviate that issue. However, I still don't recommend caching that. I cache the following. The numeric value is for the number of seconds before refreshing. If I update before then, I just use my CL Admin module to refresh the block.
Code:
Donate o Meter          300
Partners              86400
Proverb of the Day    86400
Recommended Sites     86400
Subscription Module    3600
Verse of the Day      86400
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
dean
Worker
Worker


Joined: Apr 14, 2004
Posts: 193

PostPosted: Fri Jul 22, 2005 7:13 pm Reply with quote Back to top

One of the blocks I'm using delivers this error when the cache script is applied to it:
Quote:
Parse error: parse error, unexpected T_VARIABLE in /home/alaskand/public_html/main/blocks/block-ZClassified.php on line 65


Line 65 is:
Quote:
$objCache->save($content, $fileid);


Any suggestions for change or is this block impossible to cache?
View user's profile Send private message
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 15055
Location: Kansas

PostPosted: Fri Jul 22, 2005 7:20 pm Reply with quote Back to top

Are you using my admin module? What are a couple of the lines right above that line?
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
dean
Worker
Worker


Joined: Apr 14, 2004
Posts: 193

PostPosted: Fri Jul 22, 2005 7:28 pm Reply with quote Back to top

I'm not using the admin module yet. I will install that once I get this block thingy working. It's a block that sees alot of views with perhaps 2 or three new additions a week.

Heres the last 10 lines of the block without the cache line inserted:


Code:
$ZCcontent = "<table border=\"0\" width=\"100%\">";
   $time = time();
   $query = "SELECT ad_id, cat_id, subject, views FROM ".$user_prefix."_zclassifieds_ads WHERE exp_date > $time ORDER BY add_date DESC LIMIT 10";
        $result = sql_query($query, $dbi);
   $totalAds = sql_num_rows( sql_query( "SELECT cat_id FROM ".$user_prefix."_zclassifieds_ads WHERE exp_date > $time" , $dbi) , $dbi);
   if( sql_num_rows( $result, $dbi ) != 0 ){
      $ZCcontent .= "<tr><td colspan=\"2\"><b>"._ZCLASSIFIEDTOTALADS."$totalAds</b></td></tr>";
      $ZCcontent .= "<tr><td colspan=\"2\"><b>"._ZCLASSIFIEDHOT."</b></td></tr>";
      while( $row = sql_fetch_array( $result, $dbi ) ){
         $ZCcontent .= "<tr><td valign=\"top\"><strong><big>&middot;</big></strong></td><td width=\"100%\"><a href=\"modules.php?name=ZClassifieds&file=detail&cat={$row['cat_id']}&de={$row['ad_id']}\">{$row['subject']}</a> ({$row['views']})";
         $ZCcontent .= "</td></tr>";
      }
   }
   else
   {
         $ZCcontent .= "<tr><td width=\"100%\">"._ZCLASSIFIEDNOADDS."";
         $ZCcontent .= "</a></td></tr>";
   }
$ZCcontent .= "</table>";
$content .= $ZCcontent

?>


When I insert the line, I do like this:
Code:
   }
   else
   {
         $ZCcontent .= "<tr><td width=\"100%\">"._ZCLASSIFIEDNOADDS."";
         $ZCcontent .= "</a></td></tr>";
   }
$ZCcontent .= "</table>";
$content .= $ZCcontent

// ...and save it in the cache for future use
$objCache->save($content, $fileid);
}
?>
View user's profile Send private message
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 15055
Location: Kansas

PostPosted: Fri Jul 22, 2005 7:40 pm Reply with quote Back to top

You have added a closing brace. Do you have an opening brace?
Code:
// ...and save it in the cache for future use
$objCache->save($content, $fileid);
}
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
dean
Worker
Worker


Joined: Apr 14, 2004
Posts: 193

PostPosted: Fri Jul 22, 2005 8:25 pm Reply with quote Back to top

Yes at top of block below:
Code:
if (eregi("block-ZClassified.php", $PHP_SELF)) {
    Header("Location: index.php");
    die();
}
// include the Cache-Lite package
require_once("includes/Cache/Lite.php");
// set some variables
$options = array(
  "cacheDir" => "tmp/Cache_Lite/",
  "lifeTime" => 900
);
// 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)) {
// add a message indicating this is cached output
// $content .= "\n[cached with ID=$fileid]";
}
else
{
// do the block's work here...
View user's profile Send private message
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 15055
Location: Kansas

PostPosted: Fri Jul 22, 2005 9:08 pm Reply with quote Back to top

I just noticed
Code:
$objCache->save($content, $fileid);
should be
Code:
$objCache->save($content);
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
dean
Worker
Worker


Joined: Apr 14, 2004
Posts: 193

PostPosted: Fri Jul 22, 2005 10:15 pm Reply with quote Back to top

Sorry to say, same error produced with that edit...........
View user's profile Send private message
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 15055
Location: Kansas

PostPosted: Fri Jul 22, 2005 11:07 pm Reply with quote Back to top

That error usually means that there's a missing or mismatched () or {}. Check your code real close to be sure that you have your () and {} matched properly.
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
Display posts from previous:       
Post new topic   Reply to topic

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
Forums ©
 

All logos and trademarks in this site are property of their respective owner.
The comments are property of their posters, all the rest © 2002-2008 by Raven
Proud to be listed at Lobo Links Web Directory

You can syndicate our news using the file xml

CSE HTML Validator Helped Clean up This Page! [Valid RSS] valid RSS 2.0 Valid robots.txt Stop Spam Harvesters, Join Project Honey Pot

Website engines core code is © copyright by PHP-Nuke but has been heavily patched and modified by myself and others.
PHP-Nuke is a free software released under the GNU/GPL.


:: fisubice phpbb2 style by Daz :: PHP-Nuke theme by www.nukemods.com ::

:: fisubice Theme Recoded To 100% W3C CSS & HTML 4.01 Transitional Compliance by Raven and 64bitguy ::

:: W3C CSS Compliance Validation :: W3C HTML 4.01 Transitional Compliance Validation ::

zerosum