Since PHP 5.0.5 (including 5.1), PHP has changed around the way __destruct() is called after a page is finished rendering. See the last comment on this page for more details: http://bugs.php.net/bug.php?id=33772

This attached patch invokes this suggested workaround along with correcting a previously wrong escape_string function (lots of errors with PHP 5.0.5).

However, PHP 5.0.5 further introduced a bug which won't allow this fix to work: http://www.manucorp.com/archives/php-bugs/200510/msg00520.php ... however, I have tested this on PHP 5.0.6-dev (due out very shortly) and this is also fixed with PHP 5.1 (due out in a few days apparently) so this should not be an issue.

Comments

m3avrck’s picture

Status: Needs review » Reviewed & tested by the community

Been using on dev seems to be good, no prob here.

dries’s picture

Just wondering; won't that call the session_write_close() function twice?

m3avrck’s picture

Dries, not sure I understand why that function would be called twice. PHP 5.0.5 and 5.1 changed the way this function is called (if at all) so I don't think it is being called twice. But I can assure you, without that function declared like that, Drupal won't run on PHP 5.0.5+ properly. Doesn't seem to be much out there on this issue, just lots of problems with it, solution coincides with what the main PHP developers were saying in that comment.

m3avrck’s picture

StatusFileSize
new2.14 KB

Here's an update cumaltive MySQLi patch that fixes the problem noted here: http://drupal.org/node/37863

dries’s picture

Are you saying that PHP 5.0.5 no longer calls session_write_close(), unless you register a shutdown callback for it?

I'd think session_write_close() is still called, but to late in the request. By registering a shutdown callback for it, we might be calling it twice, or does registering a shutdown callback remove the original call to session_write_close()? Or am I missing the point and is session_write_close() something special that never gets called unless used as a shutdown callback? I just want to make sure we're not doing too much work. Closing a session involves 1-2 SQL queries so ...

m3avrck’s picture

Dries it is my understanding that by using register_shutdown_function() it changes the order in which functions are called, it doesn't call them twice. So when the __destruct() is called right now in 5.0.5+, session write and close are called right after. With the register_shutdown(), it'll call __destruct() but before that executes, it now calls write and close, and then everything is destroyed.

If you have a look at the comments here (just the first few) I think their examples will explain this in better detail: http://bugs.php.net/bug.php?id=33772

Notice, that in the first 3 comments, the order of calls is changed (not duplicated), restoring this to previous versions of PHP. Oddly enough, this only affects MySQLi.

Hope that makes more sense. Apparently PHP 5.1 is due out in less than a week now (on the 24th) and this patch is going to be needed if anyone wants to upgrade to that (I'm looking into deploying that on our server as it has the potential to speed up Drupal, I'll try and get benchmarks).

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD. Thanks.

reuben’s picture

Priority: Critical » Normal

I've been seeing this message on HEAD for a few days now:

Warning: Couldn't fetch mysqli in /var/www/html/drupal-cvs/includes/database.mysqli.inc on line 346

It always appears at the bottom of the page, below the footer.

I'm running the php-5.0.5 RPM with mysqli on Fedora Core. If I revert to just 'mysql' it seems to work OK.

Am I the only person seeing this problem?

m3avrck’s picture

Hi, if you read at the top you'll notice that this is a bug with PHP 5.0.5 *only*. PHP introduced a bug into this version only that caused this. Either upgrade to 5.1.1 or downgrade to 5.0.4. Thanks!

Anonymous’s picture

Status: Fixed » Closed (fixed)