Jump to content

help with php code meaning


darkgullgray

Recommended Posts

Hey guys need some help here, i have a wordpress site, sometimes page loading on backend go on 500 error code

i know this is a generic, i activate debug mode and on log i've read this: 

PHP Warning:  mysqli_real_connect(): (HY000/1203): User __________ already has more than 'max_user_connections' active connections in /home/mhd-01/www.siteweb/htdocs/wp-includes/class-wpdb.php on line 1775

 

on line 1775 i read this:

if ( WP_DEBUG ) {
                mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );
            } else {
                // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
                @mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );
            }

            if ( $this->dbh->connect_errno ) {
                $this->dbh = null;

 

can someone explain me what this code do?

Link to comment
Share on other sites

The code just attempts to establish a database connection using MySQLi. More information can be found here:
https://www.php.net/manual/en/mysqli.real-connect.php

If WP_DEBUG is enabled, the code will handle errors as normal (e.g., display them). Otherwise, it suppresses the errors using the "@" symbol.
https://www.php.net/manual/en/language.operators.errorcontrol.php

 

As for the error, it sounds like you're hitting the limit for the number of active users connected with the database. You could check with your website host on what that limit is and whether it can be increased.

Link to comment
Share on other sites

I have been trying to solve this problem for some time without succeeding.

The max_connection value is 200 the max_user_connection value is 16 and the connections per user at any given time are 2 so I don't understand where the problem might be and how I can do to identify it.

Link to comment
Share on other sites

"User" means $this->dbuser, not the people browsing your site. Your dbuser is allowed to have 16 connections at once, which means 16 PHP scripts running at once.

Apparently you're exceeding that. Talk to your hosting provider about increasing your limits.

Link to comment
Share on other sites

  • 5 weeks later...

To resolve this issue, you can try the following steps:

Increase the maximum number of user connections: You can do this by modifying the MySQL configuration file (typically my.cnf or my.ini). Look for the max_user_connections setting and increase its value. Keep in mind that increasing this value too much may have an impact on the performance of your server, so it's important to find a balance.

Optimize your WordPress site: If your website is receiving a high number of simultaneous requests, it may be worth optimizing your site to reduce the number of database connections required. This can include caching techniques, database query optimizations, and minimizing unnecessary plugin usage.

Check for problematic plugins or themes: Sometimes, certain plugins or themes can cause excessive database connections. Try disabling all plugins and switching to a default WordPress theme to see if the issue persists. If the problem goes away, you can then enable each plugin/theme one by one to identify the culprit.

Use a database connection pooling plugin: There are plugins available for WordPress that implement database connection pooling, which can help manage and reuse database connections more efficiently. This can be useful in scenarios where your site consistently reaches the maximum number of connections.

Contact your hosting provider: If you're unable to resolve the issue on your own, reach out to your hosting provider for assistance. They may be able to provide insights specific to your server environment and offer guidance on optimizing the database configuration.

Edited by requinix
removing link
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.