Re: Time that db´s connection is keep alive

From: Date: Wed, 18 Jul 2001 00:09:15 +0000
Subject: Re: Time that db´s connection is keep alive
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-58349@lists.php.net to get a copy of this message
Marcos Mathias pressed the little lettered thingies in this order... > People! > > Someone can tell me if PHP 4 closes their connections to the DB > automatically at the end of the script? > Or I need to use the mssql_close function each time my work is done? > > Best Regards! > From: http://www.php.net/manual/en/function.mysql-connect.php The link to the server will be closed as soon as the execution of the script ends, unless it's closed earlier by explicitly calling {HYPERLINK "function.mysql-close.php"}mysql_close(). From: http://www.php.net/manual/en/function.mysql-pconnect.php Second, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use ({HYPERLINK "function.mysql-close.php"}mysql_close() will not close links established by mysql_pconnect()). So... if you use mysql_connect(), your connections are automatically closed at script completion with or without mysql_close(). If you use mysql_pconnect(), your connections stay open whether you use mysql_close() or not. Your MySQL server will close unused connections after they have been unused for a set period of time. Connections that are left open will be re-used if a request is made, so it's not like leaving a process hanging out in space. Leaving the connection open reduces the processing overhead that is necessary to open and destroy a connection on every request, so it is generally considered worth the extra memory required to keep connections open that are not being used, but probably will be used shortly. Only the person/people familiar with your server and/or web site can determine which is best: close connections at the cost of overhead for each connection or leave them open at the cost of requiring extra operating memory and system resources. Decisions, decisions... Christopher Ostmo a.k.a. tech@AppIdeas.com AppIdeas.com Innovative Application Ideas Meeting cutting edge dynamic web site needs since the dawn of Internet time (1995) Business Applications: http://www.AppIdeas.com/ Open Source Applications: http://open.AppIdeas.com/

« previous php.general (#58349) next »