Re: PHP 4.0 Bug #6033 Updated: Can't open more than one non-persistent connections to the same database

From: Date: Thu, 17 Aug 2000 01:52:35 +0000
Subject: Re: PHP 4.0 Bug #6033 Updated: Can't open more than one non-persistent connections to the same database
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-29203@lists.php.net to get a copy of this message
Hello Danny, On 13-Aug-00 10:24:27, you wrote: >> - ifx_errormsg() is causing memory leaks under both PHP3 and PHP4. You >> need to compile PHP enabling debug output to see this. >These are not "real" memory leaks. It is memory that is allocated by the >driver for the return value following the PHP guidelines using the >PHP "emalloc()" function. >This memory is released by the PHP engine on script end. >The debug build warns you because it could be real memory leaks. No, this is what a real memory leak is. Now, if the leak is harmless or not, that is another story. It is not the case that this leak should worry anybody, but harmless leaks may also turn out to be a problem until the programs exit because there is no garbage colletion that will free the leaked memory for reuse. You may assume that PHP scripts are short lived, but that is not necessarily the case. For instance I use PHP scripts as deamons to do things like polling POP mail boxes and forward messages to lists of users retrieved from a database. Also, ChrisV is adding a facility to PHP that lets it be used as TCP/Unix socket server deamons. If nobody stops these deamon scripts, any leaks will accumulate forever and soon or later small leaks will start becoming significant causing the machine to swap for an apparently insignificant problem. >I can suppress the warnings by using a variable on the stack, and letting >PHP copy the variable to the return value. This way the memory belongs to >PHP >and you get no warnings on script end. The net result is the same except >for the warnings. Yes, but it is important that all warnings go away for several reasons: - Avoid leak accumulation in deamon scripts. - Users do not get alarmed for a harmless problem. - The existence of this leak does not encover any other bugs. - The warnings do not confuse regression tests. So, if it doesn't take much for you to avoid the leak, please fix it. >> - When you call ifx_errormsg() after closing a connection in PHP3 it >> returns that connection does not exist but this does not happen under >> under PHP4. Isn't ifx_errormsg() supposed to return the last error >> message even if a connection is not established? >> >The current ifx.ec in the PHP3 CVS does not need a valid a connection >for ifx_errormsg(). >PHP3 used (3.0.7 or so) to check for an existing connection in ifx_error() , >but I removed that check long ago. You can still pass a connection id to >ifx_error(), but it is ignored. >As far as I know ifx_errormsg() never needed a connection, it does not take >a connection id as parameter but an optional error code. If you don't pass >an error code, it uses the last Informix error code if set, or SQLCODE. >So if ifx_errormsg() returns the error message "connection does not exist", >it means that this is *really* the last Informix error that occurred, and >that for some reason or other the PHP3 ifx driver tried to access the >connection you closed earlier, perhaps in the list destructor trying >to close an already closed connection (bug). If it is a bug it might be in ifx_Close in PHP 3, because the last error was not that and the connection that was passed ifx_Close is valid. As you may see in the example script, ifx_errormsg() is called after ifx_Close and without passing any connection parameters. Notice also that under PHP4 it returns an empty instead of the last error message unlike you mentioned. $informix_server="demo_on"; $database_name="xpto"; $user="informix"; $password="informix_password"; PutEnv("INFORMIXSERVER=$informix_server"); if(($connection=ifx_connect("@".$informix_server,$user,$password))) { if(($result=@ifx_query("DATABASE $database_name",$connection))) { echo "Database: $database_name, Result: $result\n"; ifx_free_result($result); } else echo "Database: $database_name Query error: ".ifx_errormsg(),"\n"; ifx_Close($connection); echo "Error: ".ifx_errormsg(),"\n"; } else echo "Connection error: ".ifx_errormsg(),"\n"; Regards, Manuel Lemos Web Programming Components using PHP Classes. Look at: http://phpclasses.UpperDesign.com/?user=mlemos@acm.org -- E-mail: mlemos@acm.org URL: http://www.mlemos.e-na.net/ PGP key: http://www.mlemos.e-na.net/ManuelLemos.pgp --

« previous php.dev (#29203) next »