ID: 33772
Comment by: webmaster at vintagegaming dot org
Reported By: msipria at suomi24 dot fi
Status: Open
Bug Type: Documentation problem
Operating System: *
PHP Version: 5CVS-2005-07-19
New Comment:
I want to enter this as a new bug report but I expect it would be
kicked out as a duplicate of 33635, which links to this bug. This
seems related in that something has changed so that my mysqli link is
closed before the shutdown_function is executed.
The following code works in all php5 versions before 5.1beta3.
<?php
function shutdown()
{
global $link;
echo mysqli_real_escape_string($link, 'foo');
}
$servername = 'localhost';
$username = 'username';
$password = 'password';
$link = mysqli_init();
mysqli_real_connect($link, $servername, $username, $password);
echo mysqli_real_escape_string($link, 'foo') . '<br />';
register_shutdown_function('shutdown');
?>
Expected Result:
foo
foo
Actual Result:
foo
Warning: Couldn't fetch mysqli in c:\program files\apache
group\Apache\htdocs\foo.php on line 7
and to further this annoying issue, why is it that the equivalent mysql
function still works in 5.1b3?
<?php
function shutdown()
{
global $link;
echo mysql_real_escape_string('foo', $link);
}
$servername = 'localhost';
$username = 'username';
$password = 'password';
$link = mysql_connect($servername, $username, $password);
echo mysql_real_escape_string('foo', $link) . '<br />';
register_shutdown_function('shutdown');
?>
Expected Result:
foo
foo
Actual Result:
foo
foo
Previous Comments:
------------------------------------------------------------------------
[2005-08-23 03:03:36] [EMAIL PROTECTED]
Reclassified as documentation issue.
------------------------------------------------------------------------
[2005-08-09 14:55:03] [EMAIL PROTECTED]
This patch fixes this problem by doing php_session_flush() before any
__destruct()'s are called:
http://www.php.net/~jani/patches/bug33772.patch
Note: It won't work if you have compiled ext/session as shared. We need
a better solution, I'm submitting this just as as temporary one.
------------------------------------------------------------------------
[2005-08-09 14:01:49] [EMAIL PROTECTED]
This is chicken/egg problem and it cannot be solved. One expect that
destructors are called before session close the other uses object for
save handlers.
------------------------------------------------------------------------
[2005-07-21 16:38:11] msipria at suomi24 dot fi
my class isn't extension of mysqli class, it just use it as object, and
with real class i have tryed session_write_close() function but mysql
connection is deat, i don't wanna restor it, i just wanna that it will
be alive at the end like now.
------------------------------------------------------------------------
[2005-07-21 00:10:05] toma at smartsemantics dot com
Adding session_write_close() to the __destruct() function will restore
the write, close, and destroy functions to their proper order.
I use a custom session handler that extends my custom mysqli class. It
automatically checks for lost database connections and attempts
reconnects, etc.
This is still a bug, but the following makes your custom session
handler viable.
public function __destruct(){
@session_write_close();
}
Without session_write_close:
starting session
connecting to database
destroying session
writing session
can't write, database connection does not exist
connecting to database
writing session
closing session
With session_write_close:
starting session
connecting to database
writing session
closing session
destroying session
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/33772
--
Edit this bug report at http://bugs.php.net/?id=33772&edit=1