Re: Multiple Includes vs. One Long Include (Functions)

From: Date: Tue, 08 Aug 2006 20:45:17 +0000
Subject: Re: Multiple Includes vs. One Long Include (Functions)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-240341@lists.php.net to get a copy of this message
Kevin Murphy wrote:
I was just wondering if there was any thought one way or another on the best practice for doing this. Lets say I have 10 functions that I want to reuse on my site. Not every page needs every function. So I move the function to an external page and then require it for the page. The question is, is it better to have all 10 of those functions in a single file that is called once from each PHP page, even though some will not be used, or is it better to put one function per include and then on each PHP page call just the functions that I need for that page? require ("all10.php"); // one long page, but only called once. vs.
require ("function1.php");    // multiple short pages with multiple calls.
require ("function2.php"); require ("function4.php"); require ("function6.php"); require ("function8.php"); --Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326
From a performance standpoint, if you're not using an opcode cache, modularizing it will be faster, since PHP won't have to compile functions that won't be used (PHP recompiles scripts every time they are run). However, if you're using an object cache like eAccelerator, APC, or Zend Accelerator, then there is no performance benefit since the opcodes are already compiled. This ignores disk accesses, but opcode caches will have everything cached in memory anyhow, so if you're using an opcode cache that wouldn't matter either. Regards, Adam Zey.

« previous php.general (#240341) next »