I am developing an application where I have a requirement that I have to include multiple files, as follows:
File1.php will include File2.php
File2.php will include File3.php
File3.php will include File4.php
Now, what will be the best and optimized way of doing these. I tried with include() but I think its slowing down my server as my server load graphs goes approx 3-5 times higher than normal server load.
These all files are heave means arround 50 KB for each file. So can anyone please suggest me what will be the best option to include these files so that it will not affect the speed of the site,
Which will be best?
require()
require_once()
include()
include_once()
OR if anyone has some other option then please tell me,
Thanks
You should reorganize your files. Have a “common.php” file that includes all the needed files. You shouldn’t have a chain like that.
I sincerely doubt a couple of includes are slowing down your server. Most web applications have tens, maybe even hundreds of PHP files. There is no way 3 extra files will slow down your application that much.
Also, the speed difference between the functions you mentioned is negligible, although you should use
include_once/require_onceinstead of their counterparts, to make sure you don’t include the same file multiple times.