"what's the performance cost of “include” in php?" Answer’s


Basically, the cost of including one big file depend on your usecase. Let's say you have a large file with 200 classes.

If you only use 1 class, including the large file will be more expensive than including a small class file for that individual class.

If you use all 200 classes, including the large file will be significantly less expensive than including 200 small files.

Where the cutoff lies is really system dependent. I would imaging that it would be somewhere around the 50% mark (where if you're using less than 100 classes in any one request, autoload).

And using APC will likely shift the breakeven point closer to less classes (so without, 100 classes used might be the breakeven point, but with it might be at 50 classes used) since it makes the large single include much cheaper, but only lowers the overhead of each individual smaller include slightly.

The exact break-even points will be 100% system dependent (how fast is your disk I/O, how fast are your processors, how much memory, etc). So the only way to know for sure on your platform is to test.

However, more is at stake than raw performance. Maintainability will suffer with one large file since it's harder to work on multiple classes at the same time (tabs in an IDE become useless). I personally would keep all the classes in separate files and make my life as the developer easier rather than making one giant monstrosity of a file.

Now, if you have facebook traffic levels, it may be worth investigating further. But if you're not, I personally wouldn't worry about it...

Wednesday, March 31, 2021
answered 11 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :