Re: [PHP] Efficieny: Include vs Array vs Function

2004-03-16 Thread Raditha Dissanayake

Hi,

On a busy site (where the milliseconds start to matter) the chances
are that the operating system has your include files cached so the
load time is probably not a factor. If you install some of the php
token caching systems (zend and others) the speed is even better.

Gentlemen I do believe I have been misunderstood. What I meant was that 
there are ways in which you can save pounds perhaps by the bucketfull 
with possibly much less effort. For example I recently ran into a $1000 
software where the most commonly used query was running against a table 
that had a non-numeric primary key. This same key was being used in 
multiple joins. Surely that can be optimized to get a huge gain in 
performance?


As to using header and footer includes I found that system really
frustrating trying to follow the html. What I have switched to is
templates where the site layout is a template and each php page
generates the content and passes it one include file that does the
final mix. this way my html developer has control over the html and
can edit it as one file most of the time.
Processing templates also consumes  a bit of extra clock cycles.

--
Raditha Dissanayake.
---
http://www.radinks.com/upload/ 
Drag and Drop Upload thousands of files and folders in a single
transfer.  (HTTP or FTP) 

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


Re: [PHP] Efficieny: Include vs Array vs Function

2004-03-16 Thread Robert Cummings
On Tue, 2004-03-16 at 05:11, Raditha Dissanayake wrote:
 
  As to using header and footer includes I found that system really
  frustrating trying to follow the html. What I have switched to is
  templates where the site layout is a template and each php page
  generates the content and passes it one include file that does the
  final mix. this way my html developer has control over the html and
  can edit it as one file most of the time.
 

 Processing templates also consumes  a bit of extra clock cycles.

You assume run time processing of templates :)

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



Re: [PHP] Efficieny: Include vs Array vs Function

2004-03-16 Thread Raditha Dissanayake
Robert Cummings wrote:

On Tue, 2004-03-16 at 05:11, Raditha Dissanayake wrote:
 

As to using header and footer includes I found that system really
frustrating trying to follow the html. What I have switched to is
templates where the site layout is a template and each php page
generates the content and passes it one include file that does the
final mix. this way my html developer has control over the html and
can edit it as one file most of the time.
   

Processing templates also consumes  a bit of extra clock cycles.
   

You assume run time processing of templates :)
 

point conceded.

Cheers,
Rob.
 



--
Raditha Dissanayake.
---
http://www.radinks.com/upload/ 
Drag and Drop Upload thousands of files and folders in a single
transfer.  (HTTP or FTP) 

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


Re: [PHP] Efficieny: Include vs Array vs Function

2004-03-16 Thread Rasmus Lerdorf
If you are that concerned about it, pear install apc.  Your include
files will be cached in memory and the only cost per include file is a
single stat() system call and looking up the opcode cache in shared
memory.

-Rasmus

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



RE: [PHP] Efficieny: Include vs Array vs Function

2004-03-16 Thread Chris W. Parker
Rob Paxon mailto:[EMAIL PROTECTED]
on Monday, March 15, 2004 9:24 PM said:

 Bear with me while I dish out some details.  My question concerns the
 efficiency of using multiple file includes versus storing segments of
 data in one include as arrays or functions.

have you considered the size of your includes? maybe cutting the size
down by splitting them into more concise files would help? in this way
you could more precisely include what you needed and leave the rest out.

just a thought.


chris.

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



RE: [PHP] Efficieny: Include vs Array vs Function

2004-03-16 Thread Jason Sheets
 Rob Paxon mailto:[EMAIL PROTECTED]
on Monday, March 15, 2004 9:24 PM said:

 Bear with me while I dish out some details.  My question concerns the
 efficiency of using multiple file includes versus storing segments of
 data in one include as arrays or functions.

 have you considered the size of your includes? maybe cutting the size
 down by splitting them into more concise files would help? in this way
 you could more precisely include what you needed and leave the rest
 out.

Sometimes having less included files with more content is more efficient
than having a lot of small files, an example would be making a seperate
include for each function, this has its advantages especially in smarty's
case but can be inefficient because you must fetch each file from disk which
has overhead.

I'd suggest profiling your code, use the PEAR Benchmark class and use PHP's
memory usage functions to determine what parts of your code are consuming
the most resources and taking the longest amount of time to execute, then
try some experiments and profile each experiment to determine the most
efficient solution.

Different versions of PHP, different application frameworks, and
applications in general will respond to optimization techniques differently,
for example there is little sense in spending 40 hours optimizing variable
usage in a program to increase performance when 75% of the program is
database server bound, your time would be better spent optimizing the SQL.

In my commericial websites I have modified my application framework not to
connect to the database, start output buffering, start the session and do
other overhead if specific constants are declared.  For example if I have
contact.php that does some mailing stuff and requires Smarty I can define
TEMPLATE_ONLY and only templating related files will be included and
initialized.

Doing this optmization made pages roughly 50% faster that did not require
session or a database connection and also reduces the load on the sql server
because you are not connecting unless you actually need the connection and
still benefit from having a single connection call instead of connecting in
each function or file.


 just a thought.


 chris.

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

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



Re: [PHP] Efficieny: Include vs Array vs Function

2004-03-16 Thread Rob Paxon
Jason Sheets wrote:
Sometimes having less included files with more content is more efficient
than having a lot of small files [...]
I'd think in my case, this is true.  Generally, nothing is in these main 
include files that aren't needed by every page.

I'd suggest profiling your code, use the PEAR Benchmark class and use PHP's
memory usage functions to determine what parts of your code are consuming
the most resources and taking the longest amount of time to execute, then
try some experiments and profile each experiment to determine the most
efficient solution.
Profiling is something I've been doing a lot of in the past week or so, 
via various debuggers.  I wasn't aware of a PEAR Benchmarking class, 
I'll have to check it out.

In my commericial websites I have modified my application framework not to
connect to the database, start output buffering, start the session and do
other overhead if specific constants are declared.  For example if I have
contact.php that does some mailing stuff and requires Smarty I can define
TEMPLATE_ONLY and only templating related files will be included and
initialized.
Doing this optmization made pages roughly 50% faster that did not require
session or a database connection and also reduces the load on the sql server
because you are not connecting unless you actually need the connection and
still benefit from having a single connection call instead of connecting in
each function or file.
I have done similar things.  For instance, sessions are only useful to 
me for people who are actually logged in, so I recently dumped my custom 
PHP sessions handler and made my own session system.  It takes a lot 
less code than my handler and only connects to the database if the user 
sends over a session id.  The database connection is then closed if the 
proceeding script doesn't need it or it is opened later if needed, in 
the case of no session.  It creates a session only through the log-in 
script.  This way, sessions are only created and read for those who 
choose to log in, which is obviously far, far less than %50 of visitors. 
 In the end, it works out to the database only being opened when needed 
and I've found this to make dramatic difference, even on my sorry old 
local enviroment.

I'm glad to see this topic got so many different responses.

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


[PHP] Efficieny: Include vs Array vs Function

2004-03-15 Thread Rob Paxon
Pardon me if this subject has been discussed, but a search of the 
archive didn't bring up much of anything.

Bear with me while I dish out some details.  My question concerns the 
efficiency of using multiple file includes versus storing segments of 
data in one include as arrays or functions.

While rebuilding the core of my web site network and, after reading some 
negative things about file includes, I was forced to rethink how I am 
structuring things.

Here are some details:
*One domain serving, with around 5 sites as subdomains currently and 
more soon to come.
*Each script on every site includes a global file that has sessions 
stuff and network-wide functions.
*Each script includes a header.php file for the specific site's layout.
*Each script includes a footer.php for ditto.
*I am currently on a virtual server, but obviously will need to move on 
to a dedicated very shortly.

It is my understanding, as disk reads are so slow, that it is not a good 
idea to include multiple files.  I always knew this, but I never really 
thought about it.

While thinking of how to optimize it, I considered merging header.php 
and the global file as one.  However, I then realized some scripts 
access the database before including the header as to dynamically change 
meta tags (say, for Articles).  I could use output buffering but, well, 
I'm not going to.

So I was thinking of making one include file that contained the following:
The former global contents (which I'd have to use a batch file to 
manage this section of the file for all sites at once, no big deal), 
header.php as a function, and the same for footer.php.

My main question is, will this, with any certainty, be more considerably 
more efficient than simply including three files?  Would it be more 
efficient to put header and footer in arrays?  Keep in mind I'd have 
to use eval() on header as all of my headers contain some php code. 
Another method that would involve using eval() would be to store the 
headers and footers in databases, but I highly doubt this would be more 
efficient than storing them in arrays or functions.

Another situation, which I am quite certain would benefit from using a 
function instead of an include, is that of scripts using forms.  These 
forms need to be included on more than one line, such as when the data 
is empty or invalid and the form needs to be shown again.  But forms are 
relatively small compared to most of my headers.

So there you have it.  How does an include compare to a function or a 
function to an array?  Is there a big difference in how the data is 
stored in memory with a function versus an array?  Would one choice be 
more efficient on a virtual server, while another more efficient on a 
dedicated (because of memory considerations)?  I'm going to just assume 
the database is not the most efficient choice here.

Thank you to all those who will respond, and even those who simply read 
this whole message.

-Rob Paxon

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


Re: [PHP] Efficieny: Include vs Array vs Function

2004-03-15 Thread Raditha Dissanayake

It is my understanding, as disk reads are so slow, that it is not a 
good idea to include multiple files.  I always knew this, but I never 
really thought about it.
Rob, you will find people who religiously avoid includes have pages that 
include dozens and dozens of images there by negating the microseconds 
gained by not using includes.  I will refrain from commenting on the 
rest of the mail primarily because i feel trying to shave a few 
milliseconds here or there by changing the includes, moving from double 
to single quotes etc are all futile efforts. Real speed and scalability 
comes from algorithms backed up by tight coding.



--
Raditha Dissanayake.
---
http://www.radinks.com/upload/ 
Drag and Drop Upload thousands of files and folders in a single
transfer.  (HTTP or FTP) 

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


Re: [PHP] Efficieny: Include vs Array vs Function

2004-03-15 Thread Rob Paxon
Thanks for the reply.  In my case there aren't many external files 
associated with the script.  1 css file per site and no images except on 
a few very specific pages.

Adding images does not negate the shaved microseconds.  I see what you 
mean, but it doesn't literally negate the saved load.  The images would 
be there whether or not the includes are used.  I'm sure there are 
millionaires out there who still pinch pennies.

That being said, I do appreciate your point, and I'm not one to go 
overboard with these kinds of things.  However, it is quite simply a 
matter of three ways to do this with one being faster.  Why would I, for 
something so fundamental to my application (used on every pageview 
across the network), not use the fastest method unless it brought some 
great inconvenience to me?

Since I am already restructuring things, it would not bring about much 
inconvenience to me.  I do expect my sites growth to be quite 
substantial over the coming year, so it can't hurt to pinch my pennies 
now, even if I currently have an embarassment of riches.

Some day a millionaire might lose everything, except for the jar of 
pennies he has on his dresser.

Raditha Dissanayake wrote:


It is my understanding, as disk reads are so slow, that it is not a 
good idea to include multiple files.  I always knew this, but I never 
really thought about it.


Rob, you will find people who religiously avoid includes have pages that 
include dozens and dozens of images there by negating the microseconds 
gained by not using includes.  I will refrain from commenting on the 
rest of the mail primarily because i feel trying to shave a few 
milliseconds here or there by changing the includes, moving from double 
to single quotes etc are all futile efforts. Real speed and scalability 
comes from algorithms backed up by tight coding.



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


Re: [PHP] Efficieny: Include vs Array vs Function

2004-03-15 Thread Rob Paxon
I have used templating for specific projects in the past (and never 
really liked it), but for this group of sites I handle both ends, so it 
loses a lot of its worth.  The factor of a caching system like Zend is 
something I have overlooked.  Currently, I wouldn't assume my virtual 
host uses it, but it is something I have planned to purchase when I make 
the move to a dedicated server.

As for trying to follow the HTML in an include system, I don't have 
too much of a problem with it personally.  Perhaps because there isn't 
much to my HTML, as I try to stick with a basic XHTML document layout 
that can be manipulated by CSS.  In other words, I never really have to 
edit my HTML, except for the static text within when the need be.

Thanks for the info.  I suppose I'll just stay with the includes for 
this round and if I know of a better way next time I do my spring 
cleaning--which probably won't have the coincidence of falling near 
spring again--I'll run with it.

- Rob Paxon

Tom Rogers wrote:
Hi,

On a busy site (where the milliseconds start to matter) the chances
are that the operating system has your include files cached so the
load time is probably not a factor. If you install some of the php
token caching systems (zend and others) the speed is even better.
As to using header and footer includes I found that system really
frustrating trying to follow the html. What I have switched to is
templates where the site layout is a template and each php page
generates the content and passes it one include file that does the
final mix. this way my html developer has control over the html and
can edit it as one file most of the time.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php