On Tue, Aug 28, 2012 at 12:11 PM, Matijn Woudt <tijnema@xxxxxxxxx> wrote: > On Tue, Aug 28, 2012 at 6:55 PM, David Harkness > <david.h@xxxxxxxxxxxxxxxxx> wrote: > > On Tue, Aug 28, 2012 at 4:39 AM, Matijn Woudt <tijnema@xxxxxxxxx> wrote: > >> > >> First of all, I believe [A] PHP is smart enough to not generate bytecode > >> for functions that are not used in the current file. Think about the > >> fact that you can write a function with errors, which will run fine > >> until you call the function. [B] (except for syntax errors). > > > > [B] negates [A]. PHP must either parse the file into opcodes or load > them > > from APC and further execute the top-level opcodes. That means defining > > functions (not calling them unless called directly), constants, global > > variables, classes, etc. > > [B] does not negate [A]. There's a difference between parsing the > syntax and defining functions, classes constants and globals, and > generating bytecode. In a 'normal' file I guess syntax definitions are > only about 5% of the total contents, the rest can be ignored until > being called. > I won't claim a deep understanding of the PHP internals, but I have enough experience with varied compiled and interpreted languages and using PHP and APC that I'm confident that the process to include a file involves: 1. Load the opcodes A. Either read the file from disk and parse the PHP into opcodes, or B. Load the cached opcodes from APC. 2. Execute the top-level opcodes Any syntax errors--even those in unreachable code blocks--will cause the script to fail parsing. For example, if (false) { function foo() { SYNTAX ERROR! } } will cause the parse to fail even though the function cannot logically be defined. PHP doesn't even get that far. PHP Parse error: syntax error, unexpected T_STRING in php shell code on line 3 > "When answering this question, please approach the matter strictly from > a caching/performance point of view, not from a convenience point of > view just to avoid that the discussion shifts to a programming style > and the do's and don'ts." While out of convenience you might be tempted to include the file in every script, when considering performance alone you should include the file only in those scripts that will make use of its contents. Peace, David