play_ Posted February 14, 2007 Share Posted February 14, 2007 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? Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 14, 2007 Share Posted February 14, 2007 unseting the varable will speed that varable up as it is now unset but the diffrence to leave it set to unset is minor ok. some programmers will agree or disagree Quote Link to comment Share on other sites More sharing options...
play_ Posted February 14, 2007 Author Share Posted February 14, 2007 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')... Quote Link to comment Share on other sites More sharing options...
btherl Posted February 14, 2007 Share Posted February 14, 2007 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. Quote Link to comment Share on other sites More sharing options...
fert Posted February 14, 2007 Share Posted February 14, 2007 If a variable is in scope, its memory will not be reclaimed that's not true, PHP has automatic garbage collection Quote Link to comment Share on other sites More sharing options...
btherl Posted February 14, 2007 Share Posted February 14, 2007 If a variable is in scope, its memory will not be reclaimed. Once it goes out of scope, it can be garbage collected. Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 14, 2007 Share Posted February 14, 2007 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. Quote Link to comment Share on other sites More sharing options...
btherl Posted February 14, 2007 Share Posted February 14, 2007 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. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted February 14, 2007 Share Posted February 14, 2007 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.