TESTING MYSQL CONNECTION LIMITS - Jul 22nd, 2019


Dave Edis of Interactive Tools offered this code to find out your database server's actual limits. Save it as a php
document and run it on your server.

The code has been updated for MySQLi with the help of Steve from Interactive Tools.


<?php

print "<h1>MySQL Connection Limit Test</h1>\n";
// display errors
error_reporting(E_ALL); // display all errors
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
ini_set('html_errors', '0'); // don't output html links in error messages

// mysql info
$hostname = "localhost";
$username = "database user name";
$password = "database password";
$database_name = "database_name";

// connect
$DBH = @mysqli-connect($hostname, $username, $password, $database_name);
if (!
$DBH) { print "Program was unable to connect to the MySQL on '$hostname'.\nThe reason given was: " .
htmlspecialchars(mysqli-error()); }
$mysqlVersion =
// get MySQL Version and connection limits
$query = "SELECT @@max_connections, @@max_user_connections";
$mysqlVersion = preg-replace("/[^0-9\.]/", '', mysqli-get_server_info($DBH));
$result = mysqli()->query($query) or die("MySQL Error: ". htmlspecialchars(mysqli_error()) . "\n");
list(
$maxConnections, $maxUserConnections) = mysqli-fetch_row($result);
if (
is_resource($result)) { mysqli_free-result($result); }


// show version and limits
print "MySQL Version: $mysqlVersion" ."\n";
print
"MySQL Max Connections: $maxConnections <a
href='http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_max_connections'> (max_connections
documentation)</a> " . "\n";
print
"MySQL Max User Connections: $maxUserConnections <a
href='http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_max_user_connections'>
(max_user_connections documentation)</a> " . "\n";
print
"<p>Done!";

?>



The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service