PHP include vs include_once (speed) [duplicate]
Possible Duplicate:
Why is require_once so bad to use?
I've read somewhere that the include_once
and require_once
stateme开发者_StackOverflow中文版nts in PHP were slower than their non-once counterparts. Is this a significant slowdown? Has there been any testing or studies of this, and has it changed in recent versions of PHP?
The speed increase is minimal and comes as a reference check is conducted to prevent code duplication. The 'once' appendage is a preventative measure against the same code being executed/included twice..this performing this check comes at a minor speed cost.
If there is ever an instance where you are using _once
look into why it is the case, is you code really built in the most efficient way? It is often better to remove the need to rely on _once
and produce better code (easier said than done!).
See:
http://forums.digitalpoint.com/showthread.php?t=1693837
http://www.phpbb.com/community/viewtopic.php?f=71&t=565933
http://www.sitepoint.com/forums/showthread.php?t=269085
http://www.quora.com/What-is-the-difference-between-functions-include-and-include_once-in-PHP
The include_once and require_once functions are slower than include and require, simply because they keep track of the files that have already been included, to avoid including them more than once.
But that shouldn't matter AT ALL, since there are probably many ways to optimize your application, way more efficient than this one.
精彩评论