Google
 
Webnews.only-4-geeks.com
Interesting places
news.only-4-geeks.com Forum Index » PHPGoto page 1, 2  Next

How best to use php5 objects between pages?

 
Jump to:  
 
DigitalDave
PostPosted: Sun Aug 31, 2008 4:15 am    Post subject: 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?
 

 
Jerry Stuckle
PostPosted: Sun Aug 31, 2008 11:06 am    Post subject: Re: How best to use php5 objects between pages?
       
DigitalDave wrote:
Quote:
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.
jstucklex@attglobal.net
==================
 

 
purcaholic
PostPosted: Sun Aug 31, 2008 11:13 am    Post subject: Re: How best to use php5 objects between pages?
       
Quote:
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
 

 
C. (http://symcbean.blogs
PostPosted: Sun Aug 31, 2008 12:34 pm    Post subject: Re: How best to use php5 objects between pages?
       
On 31 Aug, 12:13, purcaholic <purcaho...@googlemail.com> wrote:
Quote:
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.
 

 
AqD
PostPosted: Mon Sep 01, 2008 9:35 am    Post subject: Re: How best to use php5 objects between pages?
       
You can store IDs instead of real objects in session, and have a
function like "Load_Object_From_Session()" and
"Save_Object_To_Session()" to operate them - stored in shared memory
or cache storage (PHP-APC cache can provide this, see
LINK )

On Aug 31, 2:15 pm, DigitalDave <d...@noSpam.com> wrote:
Quote:
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?
 

 
Jerry Stuckle
PostPosted: Mon Sep 01, 2008 10:46 am    Post subject: Re: How best to use php5 objects between pages?
       
AqD wrote:
Quote:
On Aug 31, 2:15 pm, DigitalDave <d...@noSpam.com> 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?


You can store IDs instead of real objects in session, and have a
function like "Load_Object_From_Session()" and
"Save_Object_To_Session()" to operate them - stored in shared memory
or cache storage (PHP-APC cache can provide this, see
LINK )


(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.
jstucklex@attglobal.net
==================
 

 
DigitalDave
PostPosted: Mon Sep 01, 2008 8:05 pm    Post subject: Re: How best to use php5 objects between pages?
       
On 2008-08-31 06:06:05 -0700, Jerry Stuckle <jstucklex@attglobal.net> said:

Quote:
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.

Quote:
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.
 

 
Jerry Stuckle
PostPosted: Mon Sep 01, 2008 10:34 pm    Post subject: Re: How best to use php5 objects between pages?
       
DigitalDave wrote:
Quote:
On 2008-08-31 06:06:05 -0700, Jerry Stuckle <jstucklex@attglobal.net> said:

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.


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.

Quote:
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.

Quote:
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.
jstucklex@attglobal.net
==================
 

 
AqD
PostPosted: Tue Sep 02, 2008 6:49 am    Post subject: Re: How best to use php5 objects between pages?
       
On Sep 1, 8:46 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
Quote:
AqD wrote:
 > You can store IDs instead of real objects in session, and have a
 > function like "Load_Object_From_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.

Quote:
 So now you have multiple objects with the same id
in shared memory.

is not true.

Quote:
 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.
 

 
Jerry Stuckle
PostPosted: Tue Sep 02, 2008 10:36 am    Post subject: Re: How best to use php5 objects between pages?
       
AqD wrote:
Quote:
On Sep 1, 8:46 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
AqD wrote:
You can store IDs instead of real objects in session, and have a
function like "Load_Object_From_Session()" and
"Save_Object_To_Session()" to operate them - stored in shared memory
or cache storage (PHP-APC cache can provide this, see
LINK)


(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.

Quote:
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.
jstucklex@attglobal.net
==================
 

Page 1 of 2 .:. Goto page 1, 2  Next

Google
 
Webnews.only-4-geeks.com

Windows Update | C++ | C | PHP | JavaScript | Photoshop | Programming | Windows 2000 | Python | Windows XP | Object | Flash | Flash - ActionScript | Paint Shop Pro | Excel | PowerPoint | Access | Word | Windows 98 | Internet Explorer 6.0 | CorelDraw12 | Java | XML | asm x86 | Linux Mandrake | Linux RedHat | Outlook |  | news from newsgroups |_ | s

Web Templates

Awesome Website Templates ©

akcesoria łazienkowe lokata apteka Parkiet second life