Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #2065 > unrolled thread
| Started by | Jivanmukta <jivanmukta@poczta.onet.pl> |
|---|---|
| First post | 2011-06-10 01:02 -0700 |
| Last post | 2011-06-10 06:46 -0400 |
| Articles | 7 — 4 participants |
Back to article view | Back to comp.lang.php
object in $_SESSION Jivanmukta <jivanmukta@poczta.onet.pl> - 2011-06-10 01:02 -0700
Re: object in $_SESSION Erwin Moller <Since_humans_read_this_I_am_spammed_too_much@spamyourself.com> - 2011-06-10 11:20 +0200
Re: object in $_SESSION Gregor Kofler <usenet@gregorkofler.com> - 2011-06-10 15:43 +0200
Re: object in $_SESSION Jivanmukta <jivanmukta@poczta.onet.pl> - 2011-06-10 09:19 -0700
Re: object in $_SESSION Jerry Stuckle <jstucklex@attglobal.net> - 2011-06-10 12:34 -0400
Re: object in $_SESSION Gregor Kofler <usenet@gregorkofler.com> - 2011-06-10 18:41 +0200
Re: object in $_SESSION Jerry Stuckle <jstucklex@attglobal.net> - 2011-06-10 06:46 -0400
| From | Jivanmukta <jivanmukta@poczta.onet.pl> |
|---|---|
| Date | 2011-06-10 01:02 -0700 |
| Subject | object in $_SESSION |
| Message-ID | <22afddc3-4675-4838-af25-dc13aa75a2e0@c20g2000vbv.googlegroups.com> |
Hello,
I need your opinions about my solution of some programming probem. I
have little experience in web developement and PHP.
I have a page insert_send.html with a form. The user enters into the
form path of HTML file with bank statement and presses submit button.
Then import_statement.php program is executed. The program imports
bank statement into Statement object (which is complicated task) and
runs:
$_SESSION['statement'] = serialize($statement);
headerLocation('send_emails.php');
Then send-emails.php program is executed. It runs:
$statement = unserialize($_SESSION['statement'];
and sends emails according to statement positions (which is
complicated task, too).
My question: is the method of transferring Statement object through
session array acceptable in my case? One man told me that passing
objects through sessions is usually an error, but I don't know why.
I decided to separate importing of bank statement and sending emails
into two different files becase of complexity of these tasks.
Please help. Thanks in advance.
newbie
[toc] | [next] | [standalone]
| From | Erwin Moller <Since_humans_read_this_I_am_spammed_too_much@spamyourself.com> |
|---|---|
| Date | 2011-06-10 11:20 +0200 |
| Message-ID | <4df1e1de$0$49177$e4fe514c@news.xs4all.nl> |
| In reply to | #2065 |
On 6/10/2011 10:02 AM, Jivanmukta wrote:
> Hello,
> I need your opinions about my solution of some programming probem. I
> have little experience in web developement and PHP.
> I have a page insert_send.html with a form. The user enters into the
> form path of HTML file with bank statement and presses submit button.
> Then import_statement.php program is executed. The program imports
> bank statement into Statement object (which is complicated task) and
> runs:
> $_SESSION['statement'] = serialize($statement);
> headerLocation('send_emails.php');
> Then send-emails.php program is executed. It runs:
> $statement = unserialize($_SESSION['statement'];
> and sends emails according to statement positions (which is
> complicated task, too).
> My question: is the method of transferring Statement object through
> session array acceptable in my case? One man told me that passing
> objects through sessions is usually an error, but I don't know why.
Hi,
You must make sure that your object:
1) is defined (it's class is defined) BEFORE starting the session (via
session_start() that is. Do not use autostart in such scenarios)
2) You object cannot contain references to file-handles,
databaseconnections, etc. Only "plain" date that can be serialized.
So it can be done, but I never found myself in a situation where I
needed it.
So I tend to agree with the abovementioned "One man": Don't, unless you
must for some reason.
Regards,
Erwin Moller
> I decided to separate importing of bank statement and sending emails
> into two different files becase of complexity of these tasks.
> Please help. Thanks in advance.
>
> newbie
--
"That which can be asserted without evidence, can be dismissed without
evidence."
-- Christopher Hitchens
[toc] | [prev] | [next] | [standalone]
| From | Gregor Kofler <usenet@gregorkofler.com> |
|---|---|
| Date | 2011-06-10 15:43 +0200 |
| Message-ID | <ist719$lfm$1@dont-email.me> |
| In reply to | #2067 |
Am 2011-06-10 11:20, Erwin Moller meinte: > So it can be done, but I never found myself in a situation where I > needed it. > So I tend to agree with the abovementioned "One man": Don't, unless you > must for some reason. I frequently store objects in sessions, and have (when taking the mentioned restrictions into account) never encountered any problems. Gregor -- http://vxweb.net
[toc] | [prev] | [next] | [standalone]
| From | Jivanmukta <jivanmukta@poczta.onet.pl> |
|---|---|
| Date | 2011-06-10 09:19 -0700 |
| Message-ID | <f4c7831a-87e9-4ce2-9827-aee779a64664@hl1g2000vbb.googlegroups.com> |
| In reply to | #2075 |
> I frequently store objects in sessions, and have (when taking the > mentioned restrictions into account) never encountered any problems. I have one more question: is there any limit for maximum size of object in $_SESSION. I haven't found answer in manual but I have read somewhere in Internet that there's no such limit (there's only limit for memory PHP can serve). I ask because if HTML bank statement contains many positions, I will have big $statement object.
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2011-06-10 12:34 -0400 |
| Message-ID | <isth29$q4d$1@dont-email.me> |
| In reply to | #2077 |
On 6/10/2011 12:19 PM, Jivanmukta wrote: >> I frequently store objects in sessions, and have (when taking the >> mentioned restrictions into account) never encountered any problems. > > I have one more question: is there any limit for maximum size of > object in $_SESSION. I haven't found answer in manual but I have read > somewhere in Internet that there's no such limit (there's only limit > for memory PHP can serve). > I ask because if HTML bank statement contains many positions, I will > have big $statement object. There's no real size limit, other than memory usage. However, it's not a good idea to store huge amounts of data in the $_SESSION; it can take along time to serialize/write/read/deserialize it. I put what's necessary in it. What may or may not be required I put in a database. For instance, I will store a $user object in the $_SESSION, but it contains minimal information (i.e. userid, privileges, etc.). Other things I fetch as necessary. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | Gregor Kofler <usenet@gregorkofler.com> |
|---|---|
| Date | 2011-06-10 18:41 +0200 |
| Message-ID | <isthf2$so6$1@dont-email.me> |
| In reply to | #2077 |
Am 2011-06-10 18:19, Jivanmukta meinte: >> I frequently store objects in sessions, and have (when taking the >> mentioned restrictions into account) never encountered any problems. > > I have one more question: is there any limit for maximum size of > object in $_SESSION. I haven't found answer in manual but I have read > somewhere in Internet that there's no such limit (there's only limit > for memory PHP can serve). > I ask because if HTML bank statement contains many positions, I will > have big $statement object. The session data is frequently stored on the server's file system, which will hardly become the bottleneck. If your data would become too big to store in the session, PHP will have killed your script with an out of memory error long before. You can control the memory made available for PHP scripts with the memory_limit setting in your PHP configuration file. Gregor -- http://vxweb.net
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2011-06-10 06:46 -0400 |
| Message-ID | <isssmp$j2o$1@dont-email.me> |
| In reply to | #2065 |
On 6/10/2011 4:02 AM, Jivanmukta wrote:
> Hello,
> I need your opinions about my solution of some programming probem. I
> have little experience in web developement and PHP.
> I have a page insert_send.html with a form. The user enters into the
> form path of HTML file with bank statement and presses submit button.
> Then import_statement.php program is executed. The program imports
> bank statement into Statement object (which is complicated task) and
> runs:
> $_SESSION['statement'] = serialize($statement);
> headerLocation('send_emails.php');
> Then send-emails.php program is executed. It runs:
> $statement = unserialize($_SESSION['statement'];
> and sends emails according to statement positions (which is
> complicated task, too).
> My question: is the method of transferring Statement object through
> session array acceptable in my case? One man told me that passing
> objects through sessions is usually an error, but I don't know why.
> I decided to separate importing of bank statement and sending emails
> into two different files becase of complexity of these tasks.
> Please help. Thanks in advance.
>
> newbie
You don't have to serialize() the object; just storing it in the session
is sufficient.
Erwin's comments about what the object can contain are very valid.
However, I don't consider it an error to pass an object through a
session; it's no different than any other variable. And often it is
more efficient to pass the entire object through the session than doing
something like passing an id and rebuilding the object from a database
query.
The real "problem" here is PHP's handling of objects. When your script
ends, PHP calls the destructor for the class. But when it is
deserialized, PHP does not call the constructor. This creates a
situation where there can be more destructors called than constructors -
a clear violation of OO principals.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web