Question

I am attempting to reduce load time on my index.php. Will having my if {code} statements reduced to if {include} decrease load time or are all includes compiled anyway?

i.e.

//old code:
<?php
if (isset($_get("about")){
    my_sql code...;
    echo about me code...;
?>

//new code:
<?php
if (isset($_get("about")){
    include "./include/about.php";
?>
Was it helpful?

Solution

The include will only be included if the if condition is true. Whether this actually speeds up compilation is questionable IMO, since opening and reading another file will probably pretty much negate any speed gained through having to compile less code. You should only separate your code into separate files if it makes the code easier to read and more maintainable. For speed, use an opcode cache.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top