The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 18, 2019, 07:29:30 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: mysql_close  (Read 6002 times)
jammaster82
Lifer
*****
Offline Offline

Posts: 666


Thats craigs list for ya


View Profile
« on: February 08, 2008, 04:56:53 PM »

What if i did something like:

Code:
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>?
Logged

The watched pot, never boils... But if you walk away from it , the soup burns.  What gives?
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 1669



View Profile
« Reply #1 on: February 09, 2008, 08:24:09 AM »

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.
Logged

hai
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #2 on: February 09, 2008, 09:17:33 AM »

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?
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 1669



View Profile
« Reply #3 on: February 09, 2008, 01:30:49 PM »

Good question NBs. Also what would Unset() do?
Logged

hai
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #4 on: February 09, 2008, 01:47:45 PM »

oh LOL. I guess unset would be the correct way? I was in asp mode when I posted.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #5 on: February 11, 2008, 04:19:02 PM »

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 PHP is 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...
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #6 on: February 12, 2008, 08:43:28 AM »

so does unset() call the destructor of a class?

"new" calls the constructor, but what calls the destructor?
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #7 on: February 12, 2008, 08:51:41 AM »

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.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #8 on: February 12, 2008, 09:34:03 AM »

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.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #9 on: February 12, 2008, 09:53:52 AM »

I answered this in a new thread here:

http://www.perkiset.org/forum/php/php_destructor_call_time-t768.0.html

Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!