On Monday, January 5, 2004, at 07:05 AM, Carey Baird wrote:

(sorry if this message is repeated, I got an email saying it wasn't
delivered)

Hey,

I am creating a complete PHP driven site for the first time and I am finding
my files growing bigger and bigger. Each page of my site includes the main
function library, which itself includes an html library.


The file for the page itself contains functions that only that page
requires.

My question is if it is better, performance wise, to split all the functions
into separate files (e.g. login_funcs.php, output_funcs.php) or if it is
better to keep all functions in one file.


Would there be any performance issues with including a file, which includes
a file, which includes a file etc.? Would there be any performance issues
with including large files?


Also, I am struggling to structure my code well. I would be grateful if
anyone could point me in the direction of good resources for creating php
projects or creating web projects in general.

I've settled on a system which works well for me. Over time, you'll find one for you.


Every 'page' has this basic structure:

---
<?include('inc/header.inc');?>
[pre-html output code goes here]
<?include('inc/header.html.inc');?>
<div id='content'>
  [unique page content goes here]
</div>
<?include('inc/footer.html.inc');?>
---

header.inc in turn includes my function libraries, config files, and anything site-specific in terms of arrays or functions.

any calculations and code (eg form validation, header() redirects, cookies, etc) that needs to be done before the HTML is output is done, then header.html.inc starts the HTML with a DOCTYPE, <head>, and everything else on the page down to the main content div (the start of unique content).

after the unique content, footer.html.inc includes any other html, closes off the body and html tags, runs any post-HTML functions, etc.

in other words, each script will only have two unique areas of code or HTML... everything else is in include files, which means I can make all global changes in just a few places. this is the best separation of global and local code I have found so far (that suits me).


as such, there's possibly 8-15 include() calls for each page request... i haven't noticed any performance hit, but you could easily run a test with a bunch of nested includes of simple code, versus a flat file with all the relevant code.


personally, I'd prefer human productivity (logical separation of functions and includes) over saving a few ms of processor time on all but the most heavily busy sites.


justin french


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to