473,708 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How best to use php5 objects between pages?

A project I did awhile back stored php5 objects in elements of the
$_SESSION array between pages that were navigated on the site. There
were object classes representing teachers, and object classes
representing students that referenced teacher objects.

Then I happened to look at the temporary files created by sessions and
found much redundant data was stored in each file about the teachers
since they were referenced by every student in the same classroom.

I realize that I could have stored some persistent object data in a
database rather than in the objects. But there would be overhead either
way -- reading large session files each time the user navigates to a
new page, or querying the database each time the user navigates to a
new page.

So my question is: Are php5 objects mostly useful when their lifetimes
are only within a single page? Or what other way would objects be
useful between multiple pages on a site? When are objects stored in
sessions recommended over using database queries?

Aug 31 '08 #1
13 2405
So my question is: Are php5 objects mostly useful when their lifetimes
are only within a single page? Or what other way would objects be
useful between multiple pages on a site? When are objects stored in
sessions recommended over using database queries?
You can use the HEAP storage engine in MySQL (I suppose you are using
MySQL). Created tables an their contents are stored in memory, read-
and write access to the tables would be much more effective than
reading large session files or to storing data in MyIsam or InnoDB
storage engines.

Regards,
purcaholic
Aug 31 '08 #2
On 31 Aug, 12:13, purcaholic <purcaho...@goo glemail.comwrot e:
So my question is: Are php5 objects mostly useful when their lifetimes
are only within a single page? Or what other way would objects be
useful between multiple pages on a site? When are objects stored in
sessions recommended over using database queries?

You can use the HEAP storage engine in MySQL (I suppose you are using
MySQL). Created tables an their contents are stored in memory, read-
and write access to the tables would be much more effective than
reading large session files or to storing data in MyIsam or InnoDB
storage engines.

Regards,
purcaholic
That doesn't really answer the OPs question - he could store the
session data in a HEAP table or ramdisk - but storing the underlying
data in a HEAP would be really stupid.

OP: Storing the data in the session means that even although larger
amounts are retained, it's all read in one go - if you have to
recreate the objects at runtime you'll be making one or multiple calls
to the database. But that's at the risk of the copied data not being
current.

You have to decide based on the frequency of updates and how much of
the data will actualy be required at runtime (there's not much point
storing hundreds of objects in the session if you only use, a couple
in each script.

C.
Aug 31 '08 #3
DigitalDave wrote:
A project I did awhile back stored php5 objects in elements of the
$_SESSION array between pages that were navigated on the site. There
were object classes representing teachers, and object classes
representing students that referenced teacher objects.

Then I happened to look at the temporary files created by sessions and
found much redundant data was stored in each file about the teachers
since they were referenced by every student in the same classroom.

I realize that I could have stored some persistent object data in a
database rather than in the objects. But there would be overhead either
way -- reading large session files each time the user navigates to a new
page, or querying the database each time the user navigates to a new page.

So my question is: Are php5 objects mostly useful when their lifetimes
are only within a single page? Or what other way would objects be useful
between multiple pages on a site? When are objects stored in sessions
recommended over using database queries?

Yes, objects are quite useful. It's all in how you design your object.
For instance, it's not necessary to have a copy of the teacher object
for each student - only a way to get to the teacher object.

But I don't store large amounts of data in the session like that. I
just query the database when it's needed. It's not required on every
page, and if it is required that often, chances are it's already in the
database cache, anyway.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Aug 31 '08 #4
AqD
You can store IDs instead of real objects in session, and have a
function like "Load_Object_Fr om_Session()" and
"Save_Object_To _Session()" to operate them - stored in shared memory
or cache storage (PHP-APC cache can provide this, see
http://www.php.net/manual/en/book.apc.php )

On Aug 31, 2:15*pm, DigitalDave <d...@noSpam.co mwrote:
A project I did awhile back stored php5 objects in elements of the
$_SESSION array between pages that were navigated on the site. There
were object classes representing teachers, and object classes
representing students that referenced teacher objects.

Then I happened to look at the temporary files created by sessions and
found much redundant data was stored in each file about the teachers
since they were referenced by every student in the same classroom.

I realize that I could have stored some persistent object data in a
database rather than in the objects. But there would be overhead either
way -- reading large session files each time the user navigates to a
new page, or querying the database each time the user navigates to a
new page.

So my question is: Are php5 objects mostly useful when their lifetimes
are only within a single page? Or what other way would objects be
useful between multiple pages on a site? When are objects stored in
sessions recommended over using database queries?
Sep 1 '08 #5
AqD wrote:
On Aug 31, 2:15 pm, DigitalDave <d...@noSpam.co mwrote:
>A project I did awhile back stored php5 objects in elements of the
$_SESSION array between pages that were navigated on the site. There
were object classes representing teachers, and object classes
representing students that referenced teacher objects.

Then I happened to look at the temporary files created by sessions and
found much redundant data was stored in each file about the teachers
since they were referenced by every student in the same classroom.

I realize that I could have stored some persistent object data in a
database rather than in the objects. But there would be overhead either
way -- reading large session files each time the user navigates to a
new page, or querying the database each time the user navigates to a
new page.

So my question is: Are php5 objects mostly useful when their lifetimes
are only within a single page? Or what other way would objects be
useful between multiple pages on a site? When are objects stored in
sessions recommended over using database queries?


You can store IDs instead of real objects in session, and have a
function like "Load_Object_Fr om_Session()" and
"Save_Object_To _Session()" to operate them - stored in shared memory
or cache storage (PHP-APC cache can provide this, see
http://www.php.net/manual/en/book.apc.php )
(Top posting fixed)

A very bad idea. Object id's are only unique to the current script -
not across scripts. So now you have multiple objects with the same id
in shared memory. Additionally, you will need to keep some catalog of
what's in shared memory. And using shared memory would be very insecure.

P.S. Please don't top post.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Sep 1 '08 #6
On 2008-08-31 06:06:05 -0700, Jerry Stuckle <js*******@attg lobal.netsaid:
DigitalDave wrote:
>A project I did awhile back stored php5 objects in elements of the
$_SESSION array between pages that were navigated on the site. There
were object classes representing teachers, and object classes
representing students that referenced teacher objects.

Then I happened to look at the temporary files created by sessions and
found much redundant data was stored in each file about the teachers
since they were referenced by every student in the same classroom.

I realize that I could have stored some persistent object data in a
database rather than in the objects. But there would be overhead either
way -- reading large session files each time the user navigates to a
new page, or querying the database each time the user navigates to a
new page.

So my question is: Are php5 objects mostly useful when their lifetimes
are only within a single page? Or what other way would objects be
useful between multiple pages on a site? When are objects stored in
sessions recommended over using database queries?

Yes, objects are quite useful. It's all in how you design your object.
For instance, it's not necessary to have a copy of the teacher object
for each student - only a way to get to the teacher object.
That's exactly what we did -- we stored a reference to the teacher
object in each student object (aggregation.) But what we found upon
examining the temp file created by the session, was redundant teacher
data.
But I don't store large amounts of data in the session like that. I
just query the database when it's needed. It's not required on every
page, and if it is required that often, chances are it's already in the
database cache, anyway.
It wasn't large amounts of data in these objects. It was just redundant
objects stored in the session temp files.

But thanks for the idea that I'm beginning to get that objects aren't
useful between pages if there is composition or aggregation between
classes.
Sep 1 '08 #7
DigitalDave wrote:
On 2008-08-31 06:06:05 -0700, Jerry Stuckle <js*******@attg lobal.netsaid:
>DigitalDave wrote:
>>A project I did awhile back stored php5 objects in elements of the
$_SESSION array between pages that were navigated on the site. There
were object classes representing teachers, and object classes
representin g students that referenced teacher objects.

Then I happened to look at the temporary files created by sessions
and found much redundant data was stored in each file about the
teachers since they were referenced by every student in the same
classroom.

I realize that I could have stored some persistent object data in a
database rather than in the objects. But there would be overhead
either way -- reading large session files each time the user
navigates to a new page, or querying the database each time the user
navigates to a new page.

So my question is: Are php5 objects mostly useful when their
lifetimes are only within a single page? Or what other way would
objects be useful between multiple pages on a site? When are objects
stored in sessions recommended over using database queries?

Yes, objects are quite useful. It's all in how you design your
object. For instance, it's not necessary to have a copy of the
teacher object for each student - only a way to get to the teacher
object.

That's exactly what we did -- we stored a reference to the teacher
object in each student object (aggregation.) But what we found upon
examining the temp file created by the session, was redundant teacher data.
I didn't say keep a reference to the teacher object - I said have a way
to get to the teacher object. Such as an id to the object, etc.
>But I don't store large amounts of data in the session like that. I
just query the database when it's needed. It's not required on every
page, and if it is required that often, chances are it's already in
the database cache, anyway.

It wasn't large amounts of data in these objects. It was just redundant
objects stored in the session temp files.
Which you wouldn't have had had you not stored a reference to the
teacher object in your student variable.
But thanks for the idea that I'm beginning to get that objects aren't
useful between pages if there is composition or aggregation between
classes.
Objects are very useful between pages.

But this has nothing to do with objects. If ANY variable is a
reference to something else, storing the variable in the session stores
whatever it refers to. That's the only way it can work.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Sep 2 '08 #8
AqD
On Sep 1, 8:46*pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
AqD wrote:
*You can store IDs instead of real objects in session, and have a
*function like "Load_Object_Fr om_Session()" and
*"Save_Object_T o_Session()" to operate them - stored in shared memory
*or cache storage (PHP-APC cache can provide this, see
*>http://www.php.net/manual/en/book.apc.php)
*>

(Top posting fixed)

A very bad idea. *Object id's are only unique to the current script -
not across scripts.
An object itself has no ID. It's up to him to decide what the ID
should be (he has to implement the Save/Load functions by himself).
The uniqueness depends on his implementation.
>*So now you have multiple objects with the same id
in shared memory.
is not true.
>*Additionall y, you will need to keep some catalog of
what's in shared memory. *And using shared memory would be very insecure.
1.He can use APC cache instead of dealing shared memory by himself.
2.Shared memory or APC cache can only be as insecure as data in
session files or databases. It doesn't matter.
Sep 2 '08 #9
AqD wrote:
On Sep 1, 8:46 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
>AqD wrote:
> You can store IDs instead of real objects in session, and have a
function like "Load_Object_Fr om_Session()" and
"Save_Object_To _Session()" to operate them - stored in shared memory
or cache storage (PHP-APC cache can provide this, see
http://www.php.net/manual/en/book.apc.php)

(Top posting fixed)

A very bad idea. Object id's are only unique to the current script -
not across scripts.

An object itself has no ID. It's up to him to decide what the ID
should be (he has to implement the Save/Load functions by himself).
The uniqueness depends on his implementation.
Actually, objects do have resource id's. You just normally don't see
them. But I was referring to user-defined id's, based on your previous
comments. They are, however, still not unique across sessions.
> So now you have multiple objects with the same id
in shared memory.

is not true.
> Additionally, you will need to keep some catalog of
what's in shared memory. And using shared memory would be very insecure.

1.He can use APC cache instead of dealing shared memory by himself.
2.Shared memory or APC cache can only be as insecure as data in
session files or databases. It doesn't matter.
Which again is a very bad idea. Session files are relatively secure.
APC cache is very insecure.

Plus now you're taking memory from the rest of the system. While it
could speed up this application, it can also slow down the entire
system, depending on how much you use. You also have to be concerned
that the memory gets cleaned up properly (what happens if you put
something in it but the user never progresses to the next page?). That
requires more work - which cuts into the script performance.

Your answer is not a good one at all. There are many more problems with
it than it solves.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Sep 2 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3694
by: Christoph Nothdurfter | last post by:
Hallo! I was wondering if my PHP4-Scripts will run under PHP5 (Haeven't tried the beta yet). Does anybody know? Thank you, -Christoph
2
3264
by: Chung Leong | last post by:
Help me here. I've become a bitconfused about how PHP4 deals with objects after reading this description of PHP5: "PHP's handling of objects has been completely rewritten, allowing for better performance and more features. In previous versions of PHP, objects were handled like primitive types (for instance integers and strings). The drawback of this method was that semantically the whole object was copied when a variable was assigned, or...
8
2985
by: Rob Ristroph | last post by:
I have tried out PHP 5 for the first time (with assistance from this group -- thanks!). The people I was working with have a site that uses lots of php objects. They are having problems with speed. They had a vague idea that PHP5 has improved handling of objects over PHP4, so it would probably be faster also. In fact it seems slower. We did a few timing loops, in which a a number of objects were created and and members were...
4
1827
by: Daniel Andersen | last post by:
Hey, We are in the process of rewriting our internal management system (which was written in PHP4), and figured this would be a good time to migrate to PHP5 to get all the OO goodness it has to offer :) I am running php 5.0.3 on apache 1.3.something under slackware linux. Unfortunately I frequently get segfaults from php scripts, and they are not even scripts that do anything fancy or special. For example, in one script i got a...
7
1729
by: Mathieu Maes | last post by:
Hi there I'm quite experienced in programming in PHP4, but I would like to make a step to PHP5. I created following class which works perfectly in PHP4 : Class Nessi { // ident part
1
2462
by: Dave | last post by:
I have multiple forms that will create an object. Basically a energy efficiency measure object. The measure object will have a couple of required properties set but after that it can have 10-20 different fields that are optional per measure. How do I account for the different fields that will be posted from the different forms when I create the measure object? Should I create a constructor method with just the required fields as the...
4
2763
by: ink | last post by:
Hi all, I am trying to pull some financial data off of an HTML web page so that I can store it in a Database for Sorting and filtering. I have been thinking about this for some time and trying to find the best way to do it but I am just not experienced enough with this sort of thing to make the best decision, so any advice would be great. The data is on a number of different nested tables with in the HTML, and on a number of different...
8
2318
by: FFMG | last post by:
Hi, I am slowly moving my code to php5. But I would like to make it backward compatible in case something bad happens, (and to make sure I understand what the changes are). The way the constructors work seem to have changed quite a bit and I am not getting the same behavior across the versions. // Some simple code/
30
1898
by: Logos | last post by:
I have what may be a bug, or may be a misunderstanding on how pass by reference and class inheritance works in PHP. Since I'm relatively new to PHP, I'm hoping for a little outside help to shed some light on this! (code abbreviated for clarity) I have a parent class, DetailCollection, with a child class KeycodeTracker:
0
8788
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8697
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9290
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9159
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9061
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7925
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4713
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3151
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2508
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.