WordPress.org

Ready to get started?Download WordPress

Forums

WP 2.1 not closing mysql connection causing 500 errors (8 posts)

  1. navigadget
    Member
    Posted 7 years ago #

    Does WP not close its mysql connections properly? I've done a search and saw many others talking about these idle connections.

    I got in touch with my host (yahoo) about the persistent "500 internal server" I've been getting and here is what they said:

    * If your PHP script does not close a connection once it is done using it, that connection will remain open for approximately 20 hours before the system resets it automatically.

    * For an application which has multiple access points (for example: phpBB), this can cause the system to return errors rapidly, as connections which are no longer in use have not been closed.

    * We recommend authenticating the PHP access connection so that once the connection is no longer in use, it is closed by the PHP code.

    I'm not a mysql guru, so do not exactly know what to do here. A couple of others suggested use of mysql_pconnect() instead of mysql_connect(). Any ideas on this? If I want to try this where would I change the code.

  2. navigadget
    Member
    Posted 7 years ago #

    Can anyone else confirm mysql connections being left open?

  3. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    The connections in WordPress are opened with mysql_connect(), so they should not have to be closed as they are not persistent connections in the first place. They are closed automatically when the script ends.

    If you really want to try using mysql_pconnect, just edit wp-includes/wp-db.php. It's on line 52 towards the top. I cannot see how that would remedy your problem, however.

    And this:

    * If your PHP script does not close a connection once it is done using it, that connection will remain open for approximately 20 hours before the system resets it automatically.

    is total nonsense. PHP's own documentation says so:
    From http://php.net/manual/en/function.mysql-close.php
    Using mysql_close() isn't usually necessary, as non-persistent open links are automatically closed at the end of the script's execution.

    Now, in theory, changing to mysql_pconnect would give a performance boost, if the database server didn't totally break from attempting to handle a large number of persistent connections.

    If you really want to force close connections, just change this:

    function __destruct() {
    return true;
    }

    to this:

    function __destruct() {
    mysql_close($this->dbh);
    return true;
    }

    In wp-includes/wp-db.php.

  4. navigadget
    Member
    Posted 7 years ago #

    Otto you make a lot more sense than Yahoo Support. Thank you.

    Using phpinfo() I verified that mysql "active links" count was 1. I refreshed many times. It never changed.

    Also using phpmyadmin I looked up runtime information. There's a variable called "max used connections" which was set at 17 at the time.

    So it doesn't look like number of open connections is the issue.

    However one thing that caught my attention in "runtime information" was the number of aborted connections. This was more than 20% of all connections. What causes aborted connections?

  5. navigadget
    Member
    Posted 7 years ago #

    About aborted connections:

    The server variable Aborted_connects is incremented when:

    • When a connection packet doesn't contain the right information.
    • When the user didn't have privileges to connect to a database.
    • When a user uses a wrong password.
    • When it takes more than connect_timeout seconds to get a connect package.

    Note: if this is high it could indicate that someone is trying to break into your database!

  6. SouthBeach030
    Member
    Posted 7 years ago #

    I couldn't find "Function __ Destruct" in my wp-dp.php file.. I'm using WP 2.0.6... Is this named something else in my version?

    What can I do similarly to force SQL to close connections in 2.0.6?

    Thank you!

  7. roxer82
    Member
    Posted 6 years ago #

    I have got the some problem. I am using wordpress 2.2 but some of my plugings doesn't work when I change 'function __destruct()'
    Is there anyway to close all the connections at the end of the page?

  8. idiotprogrammer
    Member
    Posted 6 years ago #

    i'm getting a similar issue http://wordpress.org/support/topic/137344?replies=4 although I think it might be related to a plugin.

    [moderated fixed reference to topic 10/25/07 ]

Topic Closed

This topic has been closed to new replies.

About this Topic