Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder Apothem's Avatar
    Join Date
    Mar 2008
    Thanked 25 Times in 25 Posts

    Will using a custom "template" (HTML Page) impact performance?

    • By Performance, I mean speed + memory load.
    • Template denotes some sort of file that is to be eval'd

      <div id="content">
        <h2 class="title">|title|</h2>
        <div class="post">|post|</div>
    Which in turn would be be obtained via something like file_get_contents(), regular-expression-replaced to {$title} and such, and eval'd to output a basic HTML page.

    So my question is, will this method be have a large performance impact on a server vs a normal <?php echo $title; ?> or not? In what circumstances will this cause the server's performance to drop (i.e. will lots of visitors cause it to decrease or what?)

  • #2
    Regular Coder
    Join Date
    Dec 2009
    Thanked 58 Times in 58 Posts
    It will have an impact, but nothing major unless you are running it on a crappy shared host with thousands of users accessing it
    My site: JayGilford.com
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #3
    Regular Coder
    Join Date
    Mar 2006
    Thanked 37 Times in 37 Posts
    By regular-expression-replacing you mean preg_replace() ? I would advise to replace with str_replace(). String functions are faster than regexp functions.

    Of course the patterns to replace would need to be unique enough not to be met in the common page text by any chance (str_replace() will replace all strings it finds with the given replacement string).

    Also you could submit arrays to str_replace() to replace many patterns with 1 function call.

    Edit: Just in case: Also you said you would eval it to output a basic HTML page. I hope you would not use the function eval() ... There is no need for it - you could simply echo the resulting string after replacement. Also if eval() is used, it is necessary to be absolutely sure no one could attack the system by injecting some code. Normally I would use eval() only if I was sure it was absolutely safe and I was sure there was no way to avoid using this function.
    Last edited by SKDevelopment; 02-02-2010 at 02:18 PM.


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts