Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does including PHP files that contain functions in it slow the pages with those included even if not being used?

That's basically all my question is, if I have php pages that have 5,000-10,000 lines of code for a certain purpose, in my case image upload management (cropping and such), would it slow down the rest of my documents to include them on each page that doesn't use them? Basic logic tells me it of course would, but at the same time I'm not an expert, so I don't know if php acts differently than I may understand.

like image 465
Dylan Cross Avatar asked Jan 19 '12 15:01

Dylan Cross


2 Answers

include and require statements makes PHP also compile/interpret the files that you include. That does cost some computation but in 99 % of cases it won't matter... unless your site is very popular and saving that computation time is important. If that is the case, you can solve this very easily by using so called PHP Accelerators (like XCache or APC). These can be installed along with your PHP installation and cache in RAM all the compiled opcode from your php scripts. Improvements with this solution vary between 40 and 75 %.

like image 54
Radu Murzea Avatar answered Oct 30 '22 13:10

Radu Murzea


There will be a slight slowdown as the unused functions (extra code) needs to be parsed and it would also take extra memory. Apart from that no other effect.

like image 33
Yanki Twizzy Avatar answered Oct 30 '22 13:10

Yanki Twizzy