
![]() |
jammaster82
What if i did something like:
Code: $con = mysql_connect(...); $arraytofetch = select (....); while($result=mysql_fetch_array(...) ) { echo $result['answer']; } include "thenameofthisscript. php";Will i eventually run out of memory because i open up a billion connections and never close them recursively calling myself or will it close them for me? assuming i didnt care that this would never finally return back to the user, the point being if i dont close my sql connections will i be penalized for memory>? vsloathe
They will eventually die, but if I remember correctly, they will consume processes, and almost every OS has an upper limit on # of concurrent processes, even if they're zombie processes that are consuming no resources.
nutballs
this made me think of something.
Does nulling the object close the connection? ie. $db = mysql_connect( $server, $username, $password,true) or die('Could not connect to database server.'); mysql_select_db($database, $db) or die('Could not select database.'); $db = null; or would a specific close call be needed? vsloathe
Good question NBs. Also what would Unset() do?
nutballs
oh LOL. I guess unset would be the correct way? I was in
aspmode when I posted.perkiset
Nulling the connection in any case will close it... but you are NOT GUARANTEED that it is actually closed. If you mysql_close you are guaranteed that it is closed at that moment.
The only benefit to Unset over var=null is that the name is pulled from the variable pool saving a fractionally miniscule, yet tinier than a bacterial rectum amount of heap. The more important question to mashing memory and processes is how many handles MySQL will dole out at any given moment as well. By default, I think it's 100 - so at 101 attempts you will get denied and have a whole different set of problems on your hands. Since PHPis serial processing by nature, the notion of having a bazillion connections open baffles me - I cannot imagine a situation where I needed more than a couple detail handles connected to a master handle... and in most cases a single handle to the DB is plenty ample.Methinks you need to rethink either your SQL commands or schema if this is not the case... nutballs
so does unset() call the destructor of a class?
"new" calls the constructor, but what calls the destructor? perkiset
if it goes out of scope I believe it will be called, unset will do it as well. I believe if you overwrite all variable references so that it is orphaned it will be called, but I am not sure on that one.
nutballs
so then, how do you explicitly destroy an object? So that it will run the destructor?
personally I dont like relying on magical-garbage-collection. perkiset
I answered this in a new thread here:
http://www.perkiset.org/forum/ php/php_destructor_call_time-t768.0.html |

Thread Categories

![]() |
![]() |
Best of The Cache Home |
![]() |
![]() |
Search The Cache |
- Ajax
- Apache & mod_rewrite
- BlackHat SEO & Web Stuff
- C/++/#, Pascal etc.
- Database Stuff
- General & Non-Technical Discussion
- General programming, learning to code
- Javascript Discussions & Code
- Linux Related
- Mac, iPhone & OS-X Stuff
- Miscellaneous
- MS Windows Related
- PERL & Python Related
- PHP: Questions & Discussion
- PHP: Techniques, Classes & Examples
- Regular Expressions
- Uncategorized Threads