473,403 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

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 2181
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Phil Powell | last post by:
I'm sorry but I can't figure out how to explain this any better than this. In PHP we have a command "require()" that obtains a file and logically places it into another file. I cannot figure...
0
by: Billy Boone | last post by:
I have a current web application that utilizes a login to authenticate users into the application. Once I authenticate them, I store away the user's name in a Session variable. I then utilize...
134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
81
by: Matt | last post by:
I have 2 questions: 1. strlen returns an unsigned (size_t) quantity. Why is an unsigned value more approprate than a signed value? Why is unsighned value less appropriate? 2. Would there...
31
by: Yeah | last post by:
Is it absolutely necessary to include "http://" in an A HREF hyperlink? Would it be wise to remove this from one's Links page, just to save code?
5
by: Jim Carlock | last post by:
I've set up the following using an Alias in Apache... Alias /phpdocs/ "C:/Apache/htdocs/common/docs/php/" <Directory "C:/Apache/htdocs/common/docs/php"> Options Indexes FollowSymlinks MultiViews...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
8
by: Steve Kershaw | last post by:
I have a debugging/breakpoint problem that I must fix before I move on!!! When I set a breakpoint in my ASP.NET (C#) page I get the red circle with the 'A'. When I mouse over this breakpoint I...
0
by: raylopez99 | last post by:
I ran afoul of this Compiler error CS1612 recently, when trying to modify a Point, which I had made have a property. It's pointless to do this (initially it will compile, but you'll run into...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.