darkgullgray Posted May 3, 2023 Share Posted May 3, 2023 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? Quote Link to comment https://forums.phpfreaks.com/topic/316247-help-with-php-code-meaning/ Share on other sites More sharing options...
cyberRobot Posted May 3, 2023 Share Posted May 3, 2023 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. Quote Link to comment https://forums.phpfreaks.com/topic/316247-help-with-php-code-meaning/#findComment-1607973 Share on other sites More sharing options...
darkgullgray Posted May 3, 2023 Author Share Posted May 3, 2023 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. Quote Link to comment https://forums.phpfreaks.com/topic/316247-help-with-php-code-meaning/#findComment-1607981 Share on other sites More sharing options...
requinix Posted May 3, 2023 Share Posted May 3, 2023 "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. Quote Link to comment https://forums.phpfreaks.com/topic/316247-help-with-php-code-meaning/#findComment-1608005 Share on other sites More sharing options...
darkgullgray Posted May 4, 2023 Author Share Posted May 4, 2023 yes i understand this infact i wrote: "the connections per user at any given time are 2" Quote Link to comment https://forums.phpfreaks.com/topic/316247-help-with-php-code-meaning/#findComment-1608016 Share on other sites More sharing options...
requinix Posted May 4, 2023 Share Posted May 4, 2023 If you're using 16 connections and you have 2 connections per user then that means you have at least 8 users. At least if I'm doing the math correctly. Quote Link to comment https://forums.phpfreaks.com/topic/316247-help-with-php-code-meaning/#findComment-1608017 Share on other sites More sharing options...
ahmedarain24 Posted June 2, 2023 Share Posted June 2, 2023 (edited) 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 June 2, 2023 by requinix removing link Quote Link to comment https://forums.phpfreaks.com/topic/316247-help-with-php-code-meaning/#findComment-1609355 Share on other sites More sharing options...
ginerjm Posted June 2, 2023 Share Posted June 2, 2023 Ahmedarain24 : You DO realize that you are posting answers to topics that have not been active for at least or month and more. Kind of a waster of your time. Quote Link to comment https://forums.phpfreaks.com/topic/316247-help-with-php-code-meaning/#findComment-1609357 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.