Right now I have a script that has reached 400 KB in 4 files (about 3500 lines per file).
Should I split it into more files?
Does having more files have a impact on performance because of multiple require_once
calls?
When using require
or include
, PHP processes all the files as if it was one big file (imagine copy and pasting the code from the included files into your master file).
The only thing you'd really gain from splitting into separate files is organization. Organization can be huge when working with that much code, so it really depends on what works the best for you.
I have a large, 13000 line script that I combined from three others, but it's entirely view and user-management related, dealing with output and receiving input. The functions are in another, 8000 line file, and I make sure there's zero bleedover between the two. No HTML in the functions file, no SQL in the main file. Would this be different if I could use objects? Of course. Can't.
So the moral of the story is: It all depends on what makes you comfortable for the script in question. I have one other that is 5 small files because it makes more sense that way; this one makes sense as two large ones.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With