Here’s two methods to display html output: function vs include. Is there a performance hit when accessing the file system as opposed to accessing memory? If each page load has dozens, or even hundreds of includes, at what point does this become a problem?
Option 1: Html display loop using a function
foreach ($items as $item){
displayItem($item);
}
function displayItem($item){ ?>
<html output>
<?php }
Option 2: Html display loop using include
foreach ($items as $item){
include $path . 'displayItem.php';
}
//inside displayItem.php:
<html output>
Sure, disk access is much slower than memory access, that’s why disk accesses are usually cached in memory by the operating system. Even so, if you could somehow cache the output of
displayItem()(which could include a file) then save and load the cached output from memory with something like memcache, you should see significant increases in performance.