rtadams89 Posted December 9, 2008 Share Posted December 9, 2008 Hello all. Let me start by saying I have searched for this, but have not found a satisfactory answer. Probably because I am unsure of exactly what to search for. I have a website with 10+ PHP pages. There are some functions that every page uses, some functions that a few of the pages use, and some functions that only get used on one page. Currently, all of these functions are in a file named "functions.php" which is 40KB in size. As the first line of all my content PHP pages, I have included <?require($_SERVER['DOCUMENT_ROOT'].'/includes/functions.php');?> to ensure these functions are available on each page. Is this appropriate? Would it be better to have separate function files which contain "groups" of related functions, and then only include those "groups" that are needed on the particular page? Does including one large function file on every page perform better than including several smaller files on some pages? Quote Link to comment Share on other sites More sharing options...
gevans Posted December 9, 2008 Share Posted December 9, 2008 For the sake of a 40kb file I'd save myself the hassle and include the full functions file on every page, I see no need to split it! Quote Link to comment Share on other sites More sharing options...
redarrow Posted December 9, 2008 Share Posted December 9, 2008 Your doing it correctly. Just make sure you comment the page out to no what function does what. you might want to consider using include_once() apart from that it fine. Good work. Quote Link to comment Share on other sites More sharing options...
rtadams89 Posted December 9, 2008 Author Share Posted December 9, 2008 Awesome. At point should I worry about using separate include files? @redarrow: What would be the advantage of using the "include_once()" or "require_once()"? Since I am including the file at the top of the page, there doesn't seem to be a way for it to ever be accidentally loaded again... Quote Link to comment Share on other sites More sharing options...
gevans Posted December 9, 2008 Share Posted December 9, 2008 It isn't a problem on smaller systems, but it is good practice for the future. If you do try and include it twice you'll see that you get an error. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.