Jump to content

Unsetting varibles == better performance?


play_

Recommended Posts

I was wondering,

Would unset($var) increase performance, since it's cleared from memory?

And if so, would it be significant?

 

Especially if $var isn't heavy enough. Wouldn't it be more work for the system to execute unset() than to just leave it alone, if the value is small?

Link to comment
Share on other sites

Also, instead of making another thread, ill ask here:

 

Opening a mysql connection, does it use significant system resources?

 

The reason i ask is because i include the connection script whenever i connect to the database, but im thinking of including it in the header, which is included in every page. that way i dont have to type require_once('./dbconnect.php')...

Link to comment
Share on other sites

Unsetting can be essential in some cases.  If a variable is in scope, its memory will not be reclaimed.  In some memory intensive functions, I unset large arrays after I use them.

 

But in the majority of cases, there is no need.  Clearing memory doesn't help unless you're using a lot of it.

 

About the db connections, the biggest resources used are time and number of db connections.  Connecting to the db will slow down your script a little (not much if the db is on the same machine or same network).  The biggest worry I have is that lots of db connections might hit a limit on your db server.  It also makes debugging a hassle, as you don't know which connections are genuine and which are dummies.

Link to comment
Share on other sites

not much if the db is on the same machine or same network

 

I think you mean that if the database is on a server on it own then the resourses are not drawn and the database connection are a lot quicker.

 

Having a database on the same meachine as the web server is alraeady a draw back  for connection speed i think?

 

getting back to the quistion i think you need to see what database querys you could join querys and not have as one that helps.

 

also you can also goto zend and install there optimize free package to speed all things up.

Link to comment
Share on other sites

What I mean is that the connection will be fast if the db server is on the same machine as the web server.  No data needs to even go over the network.  And if the db server is on a fast local network, then network latency isn't an issue.

 

I imagine that a heavily loaded web server and db server on the same machine would interfere with each other.  I was working under the assumption that load is light.

Link to comment
Share on other sites

I think it's a matter of traffic and the size of the variable.  If you read a 10 MB text file into a variable on a page, and 10,000 users access that page at the same time, that obviously eats a lot of RAM as the system tries to process all the page loads, so it would be prudent to keep that very large variable in memory for as sort a period of time as possible.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.