469,313 Members | 2,621 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,313 developers. It's quick & easy.

Performance impact of "require"ing lots of source?

Hi all,

I have a fairly diverse range of data that I want to cache in the
session rather than pulling it from the database on every page
refresh.

The problem is is that it seems that PHP requires the class
definitions available on EVERY page, as it unserialises everything
even if it's not going to be used.

This has put me in the worrying situation of having to "require"
pretty much every class definition in my project on every page, and
I'm concerned about the performance impact this is going to have due
to PHP having to parse reams of code every time.

Are there any elegant ways around this? Am I worrying over nothing?

Cheers,
Lister

Mar 27 '07 #1
5 1814
On Mar 27, 2:17 pm, "lister" <listerofsme...@hotmail.comwrote:
Hi all,

I have a fairly diverse range of data that I want to cache in the
session rather than pulling it from the database on every page
refresh.

The problem is is that it seems that PHP requires the class
definitions available on EVERY page, as it unserialises everything
even if it's not going to be used.

This has put me in the worrying situation of having to "require"
pretty much every class definition in my project on every page, and
I'm concerned about the performance impact this is going to have due
to PHP having to parse reams of code every time.

Are there any elegant ways around this? Am I worrying over nothing?

Cheers,
Lister
Are you experiencing some specific performance problem? Or are you
just worrying before you actually have a reason to? :) Honestly, I
don't think it will cause any problems.

This was recently discussed in another thread, but you should make use
of __autoload():

<http://www.php.net/autoload>

Besides the fact that it will only load classes as necessary, it will
also save you from having all those require()'s at the top of your
page.

Mar 27 '07 #2
lister wrote:
Hi all,

I have a fairly diverse range of data that I want to cache in the
session rather than pulling it from the database on every page
refresh.

The problem is is that it seems that PHP requires the class
definitions available on EVERY page, as it unserialises everything
even if it's not going to be used.
Yes, if you're going to use a class, it must be defined first. Of
course, if you don't need to use the class, you don't need to define it.
This has put me in the worrying situation of having to "require"
pretty much every class definition in my project on every page, and
I'm concerned about the performance impact this is going to have due
to PHP having to parse reams of code every time.
If your project is that disorganized, then you will have to do it. My
projects typically have dozens of classes, and most pages require only
3-4. A few might require a couple of more.
Are there any elegant ways around this? Am I worrying over nothing?
I don't know if you're worrying over nothing or not. Are you observing
a performance problem.

Cheers,
Lister

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Mar 28 '07 #3
On Mar 27, 7:06 pm, "ZeldorBlat" <zeldorb...@gmail.comwrote:
On Mar 27, 2:17 pm, "lister" <listerofsme...@hotmail.comwrote:


Hi all,
I have a fairly diverse range of data that I want to cache in the
session rather than pulling it from the database on every page
refresh.
The problem is is that it seems that PHP requires the class
definitions available on EVERY page, as it unserialises everything
even if it's not going to be used.
This has put me in the worrying situation of having to "require"
pretty much every class definition in my project on every page, and
I'm concerned about the performance impact this is going to have due
to PHP having to parse reams of code every time.
Are there any elegant ways around this? Am I worrying over nothing?
Cheers,
Lister

Are you experiencing some specific performance problem? Or are you
just worrying before you actually have a reason to? :) Honestly, I
don't think it will cause any problems.

This was recently discussed in another thread, but you should make use
of __autoload():

<http://www.php.net/autoload>

Besides the fact that it will only load classes as necessary, it will
also save you from having all those require()'s at the top of your
page.- Hide quoted text -

- Show quoted text -
Thanks for the replies both.

No, I'm not seeing a performance problem as such - still writing the
site so proper performance testing is a long way off. I was just
trying to write defensively and was getting a bit concerned about the
amount of code that was having to be parsed on every page.
You're probably correct and it's not something I should be worrying
about yet.
If your project is that disorganized, then you will have to do it. My
projects typically have dozens of classes, and most pages require only
3-4. A few might require a couple of more.
Well yeah, typically my pages only need 3 or 4 too, but I wanted to
cache a whole lot of other info. I may have to forget this idea and
just cache stuff that is local to the current page/s.

Thanks again.

Mar 28 '07 #4
lister wrote:
Am I worrying over nothing?
Probably.

Structure the code in the most logical manner -- don't let performance
issues cloud your judgement here. If you code entirely for performance,
then in two years' time, when average CPU speed is double what it is now,
and RAM costs have fallen through the floor, you'll be sitting on a bunch
of spaghetti code and cursing yourself.

When the project's nearing completion, and after proper performance
testing, if you find that it's performing poorly, then look at installing
some PHP acceleration software, such as eAccelerator, which caches
compiled copies of your files in memory.

http://en.wikipedia.org/wiki/Optimiz...en_to_optimize
http://www.solarisinternals.com/wiki...e_Optimization
http://blog.astrumfutura.com/archives/211-.html

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
Mar 28 '07 #5
NC
On Mar 27, 11:17 am, "lister" <listerofsme...@hotmail.comwrote:
>
I have a fairly diverse range of data that I want to cache in the
session rather than pulling it from the database on every page
refresh.
Consider enabling query cache in the database instead. In terms of
disk operations, it's going to be the same or faster (reading from
the DB vs. reading from a file where session information is stored);
in terms of CPU time, much easier (no serialization/unserialization
required).
This has put me in the worrying situation of having to "require"
pretty much every class definition in my project on every page, and
I'm concerned about the performance impact this is going to have due
to PHP having to parse reams of code every time.

Are there any elegant ways around this?
Yes. Opcode caching. PHP can be configured to cache the
intermediate
bytecode, so it doesn't have to go back to the source files, unless
they have been modified.
Am I worrying over nothing?
Most likely.

Cheers,
NC

Mar 28 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Phil Powell | last post: by
reply views Thread by Billy Boone | last post: by
134 posts views Thread by James A. Donald | last post: by
5 posts views Thread by Jim Carlock | last post: by
8 posts views Thread by Steve Kershaw | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.