[thelist] PHP User Defined Functions

Brent Rieck bsr at spek.org
Wed Jan 2 12:18:34 CST 2002


Kristy,
  I'd bet that it's more time-efficient to read in one file with 100
functions than it is to open 100 files with one function - not
dramaticly faster and with only one user using a website insignifigant -
but take that to 10, 20 or 30 users hitting at once and now this poor
PHP process has to open 1000, 2000, 3000 files, probably signifigant.  

  And - on a Windows box, unless they've fixed that super *pesky*
read-locking "feature", only one php instance will be able to read a
file at any given time, leaving alot of threads blocking on read,
waiting for the opening thread to close it.

  As for organization of code, were I handed a website with 100 include
files, each one containing one function, the first thing I'd do is
concatinate all 100 files into one file, sorted alphabeticly then go
through and split them by category into some more manageable number of
functions per file.  You're right, 100 functions in a single file is not
easy, but I don't have a development environment where working with 100
one function files is easy, or even not too hard, it's just plain hard; 
and I'm not sure there are any development environments where it is easy
to work with 100 one function files.

just my opinion, I hope it helps,
Brent
bsr at spek.org

On Wed, 2002-01-02 at 08:49, Kristy Frey wrote:
> 
> --- Allie Micka <allie at pajunas.com> wrote:
> > PHP itself acts this way.  Imagine how inefficient the coding and processing
> > of any PHP script would be if you had to include a file for each of its
> > 1000s of native functions!
> 
> Let's say I will never have more than 100 user defined functions.  To what degree would the
> difference in efficiency be for:
> 
> 1. Including 100 small files at the beginning of a script
> OR
> 2. Including 1 large file that contains 100 functions (which for me is harder to maintain)
> OR
> 3. Including only the files for the functions I need in the script at the time that I need them.
> (Of my 100 or so user defined functions I may only use 5 - 10 of them in any given script.)
> 
> I fear the debate of efficiency vs. organization of code that may arise here...but...
> 
> I want to be efficient, but I also want my sites to be easy for others to maintain.  I am the sole
> web developer at this time (I was thrown into the role when our web developer quit - after he
> finally spun himself a web of code that even he could not maintain).  
> 
> I swear our old web guy used this web site on how to write unmaintainable code as his guide:
> http://mindprod.com/unmain.html
> 
> Thanks Again!
> Kristy




More information about the thelist mailing list