Opcode caching and conditional includes
| From: | Paul M Jones | Date: | Thu, 05 Jul 2007 17:29:13 +0000 |
| Subject: | Opcode caching and conditional includes | ||
| References: | 1 2 3 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-47230@lists.php.net to get a copy of this message | ||
On Jul 5, 2007, at 12:00 PM, till wrote:
On 7/5/07, Paul M Jones <pmjones@ciaweb.net> wrote:I don't know if you are wrong; I can only speak from my memory and experience. I could well be wrong myself. My understanding was that once a class is loaded via require/include to the opcode cache, it remains available on subsequent runs. That the require/include occurs within an if() is of little or no consequence to the opcode cache. E.g., this is not a problem ...On Jul 4, 2007, at 11:16 AM, Till Klampaeckel wrote:Till Klampaeckel (http://pear.php.net/user/till) has voted +1 on the proposal for Encryption::Crypt_HMAC2. Proposal information: http://pear.php.net/pepr/pepr-proposal-show.php?id=495 Vote information: http://pear.php.net/pepr/pepr-vote-show.php?id=495&handle=till This vote is conditional. The condition is: * lazy loading breaks bytecode cachingIs that so? I know that conditional class *definition* causes bytecode-cache misses, but I was not aware that conditional include/ require would cause trouble. Can you link to a reference on this?From what I understand, it attemps to cache the file, but since the include is inside a condition and runtime dependent, it would break the cache when the condition is evaluated. Or maybe even every time (disclaimer: not sure). Since lazyloading (autoload, conditional includes, etc.) in general is runtime dependent - that defeats the entire caching. I know it's convenient. ;-) Correct me if I am wrong.
if ($condition) {
include "/path/to/file.php";
}
... because the bytecode cache retains in memory the opcodes for that file, and has in-memory access to it on subsequent runs when the condition is met. It won't need to load from the filesystem every time, just the first time the file needed.
If calling require/include within an if() *is* a problem, then doing an include from within (for example) a function or method would also be a problem. This is because that function/method is called "at runtime" (as you say). I don't believe such is the case.
What *is* trouble to the opcode cache are conditional class definitions. The opcode cache doesn't know what the class "really" is until runtime, so it can't cache the opcodes for the class. It might change on each run of the script.
if ($condition) {
class Foo extends Bar {
// ...
}
} else {
class Foo extends Zim {
// ...
}
}
Again, I could be incorrect here. How this affects __autoload() is beyond me.
--
Paul M. Jones <http://paul-m-jones.com>
Solar: Simple Object Library and Application Repository
for PHP5. <http://solarphp.com>
Join the Solar community wiki! <http://solarphp.org>
Savant: The simple, elegant, and powerful solution for
templates in PHP. <http://phpsavant.com>