View Single Post
Old 03-22-10, 03:51 AM   #1
t3hl33td4rg0n
Dethklok Returns!
 
t3hl33td4rg0n's Avatar
 
Join Date: Dec 2004
Location: Kent, OH
Posts: 2,142
Send a message via AIM to t3hl33td4rg0n Send a message via MSN to t3hl33td4rg0n Send a message via Yahoo to t3hl33td4rg0n
Default LAMP Templating/CMS Performance

I recently started working on a new CMS system, that will hopefully grow into something robust enough that can be reusable in a production environment. One of the things I was concerned with was the performance using various methods. I wanted to make sure I could implement something that has a lot of features, but not a sacrifice in performance. I also wanted to minimize server load as much as possible.

Although the tests I ran were pretty elementary, it at least gave me a decent idea of how each method performed. I wasn't too surprised at the results, but the processing time of each method did have a larger margin than expected.

I had a discussion about this a few months ago on the devshed forums (which is a very good resource IMO).

link: http://forums.devshed.com/php-develo...ns-665199.html

Here is a breakdown of the methods discussed:

Method 1: Base template is your typical generic HTML page. The page contains specific areas where dynamic content is output.
1. The page data is loaded using fopen() or file_get_contents()
2. the dynamic content is generated coming from MySQL.
3. The content is injected using a simple find a replace type method using str_replace().
ex:
Code:
Before: {{BODYMAIN}}
After: <p>the quick brown fox jumps over the lazy dog</p> {{BODYMAIN}}
The process is reiterated until all dynamic bits are processed then injected into the template.
4. The modified document is output, page displays in users browser.


Method 2: Base template is a PHP page. The page contains a series of echo statements where the already processed dynamic content is output.
ex:
PHP Code:
//The PHP page
<?php
$pgTitle
= xContent::getTitle('main');
$myBlog = xContent::getContentBasic('homeNews', 'xnTwoArticle', 'id', 'ASC', '0, 10');
?>


// The HTML Page
<html>
<head>
<title><?php echo $pgTitle; ?></title>
<script type="text/javascript" src="./lib/js/myScript.js"></script>
<link rel="stylesheet" type="text/css" href="./tpl/myTpl/style.css" />
</head>
<body class="mytpl">
<table width="60%">
  <tr>
    <th>My Blog</th>
  </tr>
  <tr>
    <td><?php echo $myBlog; ?></td>
  </tr>
</table>
</body>
</head>
Method 3 (not tested): There is no template. All the static and dynamic content is contained in the database.

Here is a general flowchart of how each step method is done.




Luckily, I already have a codebase that is geared toward Method 1, so all I had to do is code something like Method 2.

So I did and ran some benchmarks today. Each page contained the same exact dynamic content and the templates themselves are the same, just processed differently.

System Testbed:
OS: Debian Squeeze 6.0
Kernel: 2.6.32 686
Apache: 2.2.14 with Suhosin Patch 0.9.8
PHP: 5.3.1-5 (using mysqli extension)
MySQL: 5.1.44

CPU: AMD Athlon 64 4000+ San Diego
RAM: 1GB DDR400 3-3-3-8 2T (for stability)
Chipset: nForce4 SLI x16

CPU:


Method 1:
Code:
Fastest: 0.0042ms
Average: 0.00445ms
Slowest: 0.0049ms
Method 2:
Code:
Fastest: 0.0021ms
Average: 0.0023ms
Slowest: 0.0027ms
Well, there you have it!
__________________


Intel QX9650 @ 3.83GHzXFX 780ieVGA GTX 560Ti8GB GSkill DDR800Creative Sound Blaster X-Fi Titanium PCI-ESeagate 1.5TB . 4x Samsung 2TB

Quote:
Originally Posted by MowTin View Post
....it's so clear how government makes things worse not better...

Last edited by t3hl33td4rg0n; 04-07-10 at 05:23 AM.
t3hl33td4rg0n is offline   Reply With Quote