Re: Re: PHP programming strategy; lots of little include files, or a few big ones?
| From: | Robert Cummings | Date: | Thu, 07 Jan 2010 05:38:00 +0000 |
| Subject: | Re: Re: PHP programming strategy; lots of little include files, or a few big ones? | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-300866@lists.php.net to get a copy of this message | ||
Daniel Kolbo wrote:
Daevid Vincent wrote:They'll mostly likely already be loaded and compiled in memory. The filesystem probably won't even get hit. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHPI had a similar issue but with classes (not functions). I opted to keep my classes short and succinct, rather than shoving all the method functionality into one all-purpose class. Instead of blindly loading all the little classes on each http request, I used (and was recommended on this list to use) __autoload(). The script would only load my classes if the individual request needed it. This helped to avoid the memory bloat. I've heard magic functions like __autoload are a bit slower, but the code is so much cleaner b/c of it. Also, an opcode cache as suggested previously would facilitate the rapid include of many small files.-----Original Message----- From: Al [mailto:news@ridersite.org] Sent: Wednesday, January 06, 2010 5:09 PM To: php-general@lists.php.net Subject: [PHP] Re: PHP programming strategy; lots of little include files, or a few big ones? On 1/6/2010 7:18 PM, clancy_1@cybec.com.au wrote:I think it's a case by case basis. Generally File I/O is expensive, but then again, as you say, having everything in a couple files is also sub-optimal for organizing and keeping things modular. I suggest you go with smaller files that are organized into logical 'chunks'. For example, functions that are used frequently are grouped into a common.inc.php rather than by topic (such as file/date/xml/forms/etc). And then use topical includes for the rest. More importantly, I suggest you get a good caching system like memecached or any of the others out there. Then you can pre-compile and load these files and the whole point becomes close to moot. ÐÆ5ÏÐ http://daevid.com "Some people, when confronted with a problem, think 'I know, I'll use XML.'" Now they have two problems.I have a flexible program, which can do many differentthings according to the type ofdata it is fed. Ideally the flexibility is achieved bycalling different functions,though when the functionality is ill-defined I sometimesjust include blocks of code.Ideally, from the point of program maintenance, each moduleshould not be too long --preferably just a page or so. This doesn't raise problemsin a compiled language, but inan interpreted language like PHP the programmer must decidewhether to lump a whole lot offunctions into a single large include file, or to includelots of little files as theparticular functions are needed. The first case can lead to memory bloat, as there arelikely to be a lot of unusedfunctions in memory on any given pass, whereas the secondcase may require lots of littlefiles to be loaded. Are there likely to be significant performance costs foreither approach, and what areyour feelings about the relative virtues of the two approaches?