unsetting or destroying objects necessary? – PHP

  php

Q(Question):

Hi,

I’m building an application with over 10thousand database entries. I
was wondering if it would be useful, regarding memory load and server
performance to unset/destroy objects at the moment when they are no
longer needed.
Will this improve performance, or will it not make any difference.

Thanks for any help.

TooN

A(Answer):

"TooN" <to**@company.com> wrote in message
news:181220031346399251%to**@company.com…

Hi,

I’m building an application with over 10thousand database entries. I
was wondering if it would be useful, regarding memory load and server
performance to unset/destroy objects at the moment when they are no
longer needed.
Will this improve performance, or will it not make any difference.

Thanks for any help.

TooN

Won’t make a great deal of differnece how may entries you have. Unsetting
variables requires processor power, so if anything, it may even make your
scripts slower.
IMHO I wouldn’t bother.

Regards
Richard Grove

http://shopbuilder.org – ecommerce systems
Become a Shop Builder re-seller:
http://www.affiliatewindow.com/affil…ls.php?mid=611
http://www.affiliatewindow.com/a.pl?590

A(Answer):

TooN wrote:

I’m building an application with over 10thousand database entries. I
was wondering if it would be useful, regarding memory load and server
performance to unset/destroy objects at the moment when they are no
longer needed.
Will this improve performance, or will it not make any difference.

As another poster said, it probably won’t make a big difference;
however, suppose you grab 50K (too farfetched?) from the database and
have 200 simultaneous users — that makes 10M of data loaded into RAM
while each script is executing … maybe you’d like to limit that only
to the parts of the script where it is needed only. Anyway they’ll be
unset when you tell PHP to (with unset()) or at the end of the script.

I tend to do it for "large" things

<?php
// …
$res = mysql_query($sql)
// deal with it
unset($res);
// …
?>

<?php
// …
$data = file(‘http://www.example.com/large_page.html’);
// extract data
unset($data);
// …
?>

–= my mail box only accepts =–
–= Content-Type: text/plain =–
–= Size below 10001 bytes =–

A(Answer):

In article <3f***********************@mercury.nildram.net>, Richard
Grove wrote:

"TooN" <to**@company.com> wrote in message
news:181220031346399251%to**@company.com…

Hi,

I’m building an application with over 10thousand database entries. I
was wondering if it would be useful, regarding memory load and server
performance to unset/destroy objects at the moment when they are no
longer needed.
Will this improve performance, or will it not make any difference.

Thanks for any help.

TooN

Won’t make a great deal of differnece how may entries you have. Unsetting
variables requires processor power, so if anything, it may even make your
scripts slower.
IMHO I wouldn’t bother.

Regards
Richard Grove

Just what I thought.
Thanks for answering!

TooN

A(Answer):

I (Pedro Graca) wrote:

<?php
// …
$res = mysql_query($sql)
// deal with it
unset($res);

oops … that should have been
mysql_free_result($res); // …
?>


–= my mail box only accepts =–
–= Content-Type: text/plain =–
–= Size below 10001 bytes =–

A(Answer):

In article <br************@ID-203069.news.uni-berlin.de>, Pedro Graca
<he****@hotpop.com> wrote:

Thanks for thinking along with me,
although I don’t expect 200 simultaneous users, we keep it in mind!

Toon

As another poster said, it probably won’t make a big difference;
however, suppose you grab 50K (too farfetched?) from the database and
have 200 simultaneous users — that makes 10M of data loaded into RAM
while each script is executing … maybe you’d like to limit that only
to the parts of the script where it is needed only. Anyway they’ll be
unset when you tell PHP to (with unset()) or at the end of the script.

I tend to do it for "large" things

<?php
// …
$res = mysql_query($sql)
// deal with it
unset($res);
// …
?>

<?php
// …
$data = file(‘http://www.example.com/large_page.html’);
// extract data
unset($data);
// …
?>

A(Answer):

TooN <to**@company.com> wrote in message
news:<181220031346399251%to**@company.com>…

I’m building an application with over 10thousand database entries. I
was wondering if it would be useful, regarding memory load and server
performance to unset/destroy objects at the moment when they are no
longer needed.
Will this improve performance, or will it not make any difference.

Surprise, surprise… Using unset() on an object DOES NOT free up
any memory in PHP 4. Zurab Davitiani posted his observations on the
subject to this newsgroup back in October:

http://groups.google.com/groups?hl=e…ws.prodigy.com

This is expected to be resolved in PHP 5, which implements
destructors.
Until then, your best bet for a high-performance memory-intensive
application is to ban OOP from it (which, in my book, is always a good
idea to consider when working with PHP. PHP does not run on a virtual
machine and has no system objects; all calls to OS and other low-level
software such as database engines are procedural, so there is no need
to introduce the overhead of OOP, unless you are into refactoring, in
which case you are simply buying shorter application development time
with lower application performance).

Cheers,
NC

LEAVE A COMMENT