Caching PHP applications using …

Caching PHP applications using Smarty

Using Smarty is daunting at first, there’s so much it can do. Here’s a way to take advantage of Smarty’s caching functionality in your pre-existing applications.

What we’re going to do is use the PHP4 output buffering and cache the output of your script through that.
Create a simple template on your webserver somewhere. It doesn’t even have to reside in the visible path of the server. In fact, it probably shouldn’t! In that file will be one Smarty variable, $text. This variables is going to hold the entire contents of your script output.
Your script is going to have various inputs that define what gets shown, ie. username, message number, etc. We’re going to cache the output based on those bit of information. In our example that’ll be the uid, $uid of the user.

—–/home/www/include/templates/text.tpl—–
{$text}
—–/home/www/include/templates/text.tpl—–

—–/home/www/htdocs/test.php—–
require(‘Smarty.class.php’);
$smarty = new Smarty;
$smarty->caching = true;
$template = “/home/www/include/templates/text.tpl”;

if($smarty->is_cached( $template, $uid )==false)
{
  // Create new content, cached data is stale or isn’t cached.
  $text = “Hello World”;
  ob_start();
  // Call legacy code that prints directly to the browser
  // Get data from database, do other expensive things.
  $text .= ob_get_contents();
  ob_end_clean();
  $smarty->assign(‘text’, $text );
}

$smarty->display( $template, $uid );
—–/home/www/htdocs/test.php—–

If your legacy code has to interogate the database then you’re saving a huge amount of time doing this. Even if it’s nothing but print statements, chances are Smarty will do it quicker if it’s cached.

Google's great, or more specif …

Google’s great, or more specifically, it’s great to find old stuff on the Internet. Unlike real life, if you remember saying something on a mailing list or webpage, but not sure when or where you wrote it, fire up Google and go searching.Someone mailed me asking if I had considered doing a Postfix version of my install-sendmail script. I had. *grin*

Spackle kicks ass. It's a "fle …

Spackle kicks ass. It’s a “flexible client/server architecture for the gathering and displaying of statistics, primarily suited to monitoring servers.” I had it collecting data on almost all our servers within a few hours. It’s also got a simplistic but capable web-interface for inspecting the data. The default collection of monitoring agents is Linux specific so YMMV if you’re using something else.
I did run into some trouble and attempted to mail the author but his mail server couldn’t resolve my work domain, which doesn’t surprise me anymore. Here’s what I suggested:

Add this line to spackle.sh somewhere:
export TERM=xterm
because of this error message when spackle.sh is run from cron, “Your terminal lacks the ability to clear the screen or position the cursor.”
Found the solution at http://www.flora.org/lynx-dev/html/month042000/msg00441.html
This occurs on RH6.2 but not in RH7.2, that link above has some info which might explain why.

Add full path to nc:
nc -> /usr/sbin/nc
nc is installed in /usr/sbin/ by default when I used an rpm of netstat.

Change bang line to
#!/bin/bash2
RH7.2 seems to use bash2 by default, 6.2 uses bash.

When I started reading this ar …

When I started reading this article I wasn’t sure why I opened it, but then it got into the juicy bits! It’s great that a Mac user can stand back and examine his community with a critical eye. It doesn’t happen often and they are usually harrassed by their fellow users. Yes, yes, there’s plenty wrong with Linux too, but we all know it’s “better” than the Mac any day! *grin*

Tab rollin'Linux desktop appli …

Tab rollin’
Linux desktop applications – features a few apps I use and can recommend.
Developing a Linux command-line utilityBest practices and thoughtful coding make for solid command-line tools.
Free CIV, screenshots and Google directory – I’m not into these types of games but I’m impressed by the fact that they’re still working on it.
BottomQuark: The Smoking Gun of AIDSWere well-intended medical treatments ultimately responsible for the rise of the HIV virus?
Son, he said… – There’s some truth in this, and I happen to know someone this piece describes perfectly!