Hi all, I have a doubt whether using the function include(); 5 or 6 times in a PHP page for inserting the code poses any problem?? Please suggest me with all your experiances....... Thank you in advance
I would use include_once() rather than include() saves issues if you include a page more than once. But 5/6 times is ok. You wont see any slowdown.
Including 5-6 files is not going to be an issue if they are local. If you were doing includes that were url based it may be an issue but for local files which have code it's not an issue.
I have created in the past a basic template which had 10 include() for ads, navigation bars, latest news, links and other features on a website and there were no issues whatsoever
I just use the basic <?php include"filelocation";?> I use that quite a bit on my sites, never had a problem with it. Doesn't slow my sites down in the slightest.
If you have a large system it can really slow things down. For instance I have a site that requires around 20 includes per page, the issue is you are going to the file system and parsing the file each time. To REALLY speed things up you can use APC. This will store all the compiled includes in memory far next time.
It depends on what the included files are doing and what type of file system is being used (e.g., NFS on shared hosts can be slow). If your code is reasonably optimized and the file system is decent, you won't have any problem.
Hi I am going to include just header, navigation, footer, ads, like that as many as 10 to 15 includes. So does that slow down the page loading....... . They dont have any functions. Just code.
will not slow down the page.. infact - its a good practise to use includes.. because if you want any changes laters, you dont have to modify all the pages, you will just modify one page that will effect all the pages
Just be careful not to get yourself into a loop. But as everyone's said already, multiple includes are never a problem, as all PHP really does is file_get_contents() the code and eval() it. You could try Op(eration)Code caching if its needed.
I did an experiment before and the more includes you use, the speed of your script decreases. The decrease can be negligible though. But if you're meticulous with speed, you might have to put this into consideration.