Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include all functions in the php file I need or just the functions I need?

So here is what I want to do.

  1. The first option is to write each function in different php file each one and then include all of them in a php file that is called include functions.php and whenever I create a new page , let's say index.php I just include "functions.php";

    Why do I need to do that? Because I'll just have to include only one file and all the functions will be included. Now the problem probably will be the server load. I'm not sure how much uncalled functions affect the performance.

  2. The second option is to create again the files I need, team them up and then whenever I need a function just call it. The drawback of this is that I'll have more work to do in order to categorize and I'll have to include a lot of files

So I want to ask, does the first option increase the cpu and memory load that much that I have to go to the second one? Are there any performance issues with the first way or the functions that are not being used are not parsed at all by the php ?

like image 386
viper Avatar asked Jul 01 '11 12:07

viper


1 Answers

Disk is a slowest part of the server, so in this case variant "all functions in 1 file" will give you little more performance, theoretically.

But I don't recommend you to create "functions.php", better way is OOP. Create classes (objects) with methods, use autoloaders and PSR-0 standard and you will forget about "include" and "require" at all.

like image 78
OZ_ Avatar answered Nov 14 '22 23:11

OZ_