Re: include selectively or globally?

From: Date: Tue, 28 Aug 2012 01:49:15 +0000
Subject: Re: include selectively or globally?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-318896@lists.php.net to get a copy of this message
On Mon, Aug 27, 2012 at 6:54 PM, Matijn Woudt <tijnema@gmail.com> wrote: > On Mon, Aug 27, 2012 at 10:56 PM, Haluk Karamete > <halukkaramete@gmail.com> wrote: >> >> Now, the question is... should you use a global include that points to >> this library - across the board - so that ALL the pages ( including >> the 90% that do not need the library ) will get it, or should you >> selectively add that include reference only on the pages you need? >> > > Since searching for files is one of the most expensive (in time) > operations, you're probably best off with only a single PHP file. Maybe I misinterpreted the question, but I don't think I agree. If you have a 50K PHP file that's only needed in only 10% of the pages, then, when solely considering performance, that file should only be included on the 10% of the pages that actually use the file. Now, there are reasons where you might want to include the file globally (maintenance purposes, etc.) Loading the 50K of PHP code requires building up all of the associated infrastructure (zvals, etc.) for the user code (even if APC is used, the cached opcode/PHP bytecode still has to be parsed and built up for the user-defined classes and functions per request, even if they're unused), is certainly going to perform more slowly than selectively including the library on only the pages that need the library. Adam -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.com

« previous php.general (#318896) next »