View Single Post
Old 03-22-10, 10:15 AM   #2
Join Date: Mar 2004
Posts: 15,486
Default Re: LAMP Templating/CMS Performance

Nice little demonstration. With PHP there's only so much you can do to speed it up though. In the end, the page still has to be compiled and displayed when it's loaded. If you want to minimize server load, then it may be best to implement something like AJAX, where database calls are only made when necessary.

A few questions:

Why do you use str_replace to fill in your fields? PHP can be initiated anywhere in the page. Wherever you need the data, put in a <?php tag and echo the data, then close it ?>. That's one reason why Method II is much better. The overhead involved in searching a document for a string and then replacing it is insane.

I always use HTML templates in my pages. Typically the header, footer, and navigation sections are always included in simple HTML templates that I include into the main page. This makes updating your site very easy, since editing 6-7 pages boils down to editing 4 short files (CSS is stored in a separate page as well).

I only use file_get_contents() when I load in HTML from a separate page to parse. If you are including a functions file, always use require, so if the page is not found an error will be thrown. Could also prevent some of your page's code from being displayed.
ViN86 is offline   Reply With Quote