SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2006
    Posts
    443
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Which will perform faster?

    PHP Code:
    <?php
    $me
    ="geek";
    echo 
    $me;
    echo 
    "<br/>";
    echo 
    "Hi";
    ?>
    or
    PHP Code:

    <?php
    $me
    ="geek";
    echo 
    $me;
    ?>
    // then put the break as HTML outside the PHP code,


    <br/>

    // and then complete the code with another <?php tag:
    PHP Code:
    <?php
    echo "Hi";

    ?>

  2. #2
    SitePoint Addict Kokos's Avatar
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think it matters a lot, but I do know it would get insanely annoying to break up your php blocks for some html text and make your code really awful to look at or handle.

    Taking over the web one pixel at a time.
    Currently working @ CodeCreators

  3. #3
    SitePoint Zealot
    Join Date
    Jun 2010
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The one with 1 echo statement will perform the fastest.

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Did you try? Did you notice a difference? If you did, try again
    Maybe if you would execute that piece of code thousands of times...

  5. #5
    Floridiot joebert's Avatar
    Join Date
    Mar 2004
    Location
    Kenneth City, FL
    Posts
    823
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In my test with Apache Bench, I can get ~600 requests per second from the first form, whereas I can only get ~300 requests per second from the second way you have it there.

    I don't remember if PHP flushes the output buffer when it encounters an HTML token, but if it does I'm sure that's got something to do with the difference.


Bookmarks

Posting Permissions

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