Click to See Complete Forum and Search --> : php self cleanup.


cafrow
01-23-2006, 10:29 PM
I have read in mutiple places that PHP runs a resource cleanup code, basicly it detroys un-needed variables for you. Since hearing this I have not been closing my MySQL connections. Basicly I am wondering if PHP really does close the connection for me, and if it does does it close it at the end of the script or what? Should I still be closing my own connections or is it really not needed?

Thanks

NogDog
01-23-2006, 10:39 PM
As per http://www.php.net/mysql_close :

Using mysql_close() isn't usually necessary, as non-persistent open links are automatically closed at the end of the script's execution. See also freeing resources (http://www.php.net/manual/en/language.types.resource.php#language.types.resource.self-destruct).

speedy
01-23-2006, 10:40 PM
From php manual, http://www.phpbuilder.com/manual/function.mysql-connect.php

Note: 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 mysql_close().

Note: You can suppress the error message on failure by prepending a @ to the function name.

Hope this help

cafrow
01-23-2006, 10:47 PM
THanks guys. This makes me a very happy person.

ShrineDesigns
01-23-2006, 11:41 PM
from my experience, persistent mysql links are not needed and can cause connection problems

PHP doesn't really clean up anything other than old session or temporary files that may be lying around (this does not apply to windows' FAT file systems)

although php does allots variables, arrays, resources, and objects to memory (which are freed when the script terminates or ends) you can free up memory space by using unset(), in most cases it is unnecessary to explicitly unset these, but can have a profound impact on scripts that use large amounts of resources or are heavily used

chazzy
01-23-2006, 11:48 PM
from my experience, persistent mysql links are not needed and can cause connection problems

My understanding is that they stay around until the server itself closes them (requires a timeout setting, I believe)

ShrineDesigns
01-24-2006, 12:01 AM
there is a setting in the php.ini file that dictates how long a persistent connection remains open

i have found that it is best to use non-persistent connections, i have ran into less problems as a result