5

It's a simple question, but which is faster between a simple html page with php echoing results or a html page build only by php dom ?

Thank you for your answers and your advices!

3
  • please be kind! It's a simple question Commented May 23, 2012 at 3:41
  • 3
    I don't see why people are downvoting (besides being a possible duplicate), this question should be useful for future reference. Commented May 23, 2012 at 3:42
  • Thank you Fabricio, i think too ^^ Commented May 23, 2012 at 3:47

3 Answers 3

3

Too many unknown variables …

When using DOM you can put much information very fast into your tree; using echo you need to track your (meta)data somehow else. To print a static page you should not use DOM. To print a page that is heavily modified during construction you would probably want to use DOM.

There is no right answer to this question. You need to do a benchmark for your specific usecase.


But you might value your time as well … I hope so. Even if it might be slower to render a page using DOM, it will be easier to let your project grow. Writing module systems that employ echo calls soon become a mess.

Sign up to request clarification or add additional context in comments.

4 Comments

It will be a web application. The header will stay the same but content will change and sidebar too... I want clean code who will be easy to change with my page.class.php. How can i beanchmark the 2 pages to compare? Do you know if it will have a big impact? Thank you for your answer
Please see my update. But sorry, no I don't have actual measure data. But I have experience maintaining messy PHP code. ;-)
I'll make some test to night and i'll bring some feed back ^^
For a simple page with doctype,metas, title, it take 6ms and in pure html it take 3ms... But i'll continue the dom way to check how a big page is impacted
3

There is nothing faster than plain HTML file being accessed directly. And best served with an .html extension.

PHP code has to go through the PHP interpreter, which is an additional step.

And this is the case for every server side language (C#, PHP, Python, Java, Node.js, etc)

2 Comments

What is the performance hit of using a .php file over a .html file when both are just serving plain HTML? ie How expensive is it for the PHP Apache module to be loaded? On my server, PHP is parsed in files with a .html extension (because I prefer it to .php - which I think looks icky) so would it worth either changing this or perhaps setting up a new extension that doesn't invoke the PHP parser?
The performance is the same as for any other PHP file. Using file extensions like (.php and .html) can now be considerd outdated and best be avoided. This question was asked 10 years ago. Today I would suggest moving to a modern language that compiles to native executable code (i.e. Golang), and avoid additional steps like loading of php modules, node modules, and dependencies, as well as using interpreters, virtual machines, etc.
1

You should try some MVC Framework like Code Igniter

Wrting the same code again and again is not good.

You can split ur website like this

 ____________________________________
|                HEADER             |  // Header.php
|___________________________________| 
|                     NAV BAR       |  //menu.php
|___________________________________|
|                                   |  
|                                   |
|    Content                        | //Content {Different pages based on menu clicked}
|                                   |
|___________________________________|
|          FOOTER                   | 
|___________________________________|  //Footer.php

so All your pages will be like this

<?php
    include(header.php);
    include(menu.php);

    //based on menu clicked 
   include('clickedPage.php')

  //Finally
  include('footer.php');
?>

1 Comment

Some people told me thant codeignitier code isn't correct and i must don't touch this framework.... And the base question was not this. But ty for your advices

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.