As you can see I at least temporarily implemented mtmosier code and it does work although I extended the time to 250mil seconds. I tried it on the live server during very busy time but guess what, the message was displayed just like expected. However, above the message appeared the Error again...lol
i.e. mysql_pconnect(): User XXXX has already more than 'max_user_connections' active connections in /home/public_html/users/db.inc.php on line 30
Line 30 this time because of the extra code.
Now I feel a little better because at least they get some message telling them something and of course not to go away..lol
I will try to use myconnect instead of pconnect and will let you know my results.
About closing the connection, I don't see where it ever gets closed?
class CMySQL
{
var $host, $sock, $port, $user, $passwd, $db, $connected, $link;
function connect()
{
if ( $this->connected )
return;
if (strlen($this->port)) $this->port = ":".$this->port;
if (strlen($this->sock)) $this->sock = ":".$this->sock;
// line 25 ---- $this->link = mysql_pconnect( $this->host . $this->port . $this->sock, $this->user, $this->passwd );
$attempts = 10;
$delay = 2500000; // Delay in microseconds
for ( $i = 0; $i < $attempts; $i++)
{
if ( !$this->link = mysql_pconnect( $this->host . $this->port . $this->sock, $this->user, $this->passwd ) )
{
usleep($delay); // Not available on windows before PHP 5.0
}
else
{
break;
}
}
if ( !$this->link )
{
echo "<table align=center border=\"1\" cellpadding=\"2\" cellspacing=\"2\" style=\"border-color:#9C21A5\"><tr><td bgcolor=\"#9C21A5\">";
echo "<font color=white face=\"Arial, Helvetica, sans-serif\"><b>Community Server is Temporaraily Busy!</b></font>";
echo "</td></tr>";
echo "<tr><td>";
echo "Our Community is currently in HIGH DEMAND!<br>USE your browers refresh or back button in just few seconds.</b><br>Please, Please, Please try again. We appreciate your patience and we very, very, very SORRY for the inconvenience.<br><br>We are experiencing some growing pains and we know this hurts you, so an Error report has been sent.";
echo "</td></tr></table>";
exit;
}
if ( $this->link )
$this->connected = TRUE;
else
$this->connected = FALSE;
}
function select_db()
{
return mysql_select_db( $this->db );
}
}
$MySQL = new CMySQL;
$MySQL->host = $db['host'];
$MySQL->sock = $db['sock'];
$MySQL->port = $db['port'];
$MySQL->user = $db['user'];
$MySQL->passwd = $db['passwd'];
$MySQL->db = $db['db'];
$MySQL->connected = FALSE;
$MySQL->connect();
$MySQL->select_db();
function db_connect()
{
global $MySQL;
global $BUG_REPORT_EMAIL;
global $MySQL;
if ( !$MySQL->select_db() )
{
echo PrintErr( _t("_DB_ACTIVATION_FAILED") );
$msg = "Error in $_SERVER[PHP_SELF]: " . mysql_error();
db_report_error( $msg);
}
return true;
}
function db_res( $query, $error_checking = 1 )
{
global $BUG_REPORT_EMAIL;
global $MySQL;
$res = mysql_query( $query, $MySQL->link );
if ( $error_checking && !$res )
{
echo PrintErr( _t("_DB_ACCESS_ERROR"));
$msg = "Error in $_SERVER[PHP_SELF]: " . mysql_error() . "\nQuery: '$query'";
db_report_error( $msg);
}
return $res;
}
function db_report_error($msg){
global $DEBUG;
global $BUG_REPORT_EMAIL;
if ($DEBUG) {
trigger_error($msg,E_USER_ERROR);
} else {
mail( $BUG_REPORT_EMAIL, "Error", $msg);
}
exit;
}
function db_arr( $query )
{
global $BUG_REPORT_EMAIL;
global $MySQL,$DEBUG;
$res = mysql_query( $query, $MySQL->link );
if ( !$res )
{
$msg="Error in $_SERVER[PHP_SELF]: " . mysql_error() . "\nQuery: '$query'";
echo PrintErr(_t('_DB_ACCESS_ERROR'));
db_report_error( $msg);
}
$arr = mysql_fetch_array( $res );
return $arr;
}
function fill_array( $res )
{
global $MySQL;
if (!$res)
return false;
$i = 0;
while( $r = mysql_fetch_array( $res ) )
$arr[$i++] = $r;
return $arr;
}
function getParam( $param_name )
{
if ( !$line = db_arr( "SELECT VALUE FROM GlParams WHERE Name = '$param_name'" ) )
return false;
return $line[VALUE];
}
function getParamDesc( $param_name )
{
if ( !$line = db_arr( "SELECT `desc` FROM GlParams WHERE Name = '$param_name'" ) )
return false;
return $line[desc];
}
function setParam( $param_name, $param_val )
{
$param_val = str_replace_mysql ($param_val);
if ( !$res = db_res( "UPDATE GlParams SET VALUE = '$param_val' WHERE Name = '$param_name'" ) )
return false;
return true;
}
function str_replace_mysql($str)
{
$option = $str;
$option_tmp = "";
$len = strlen($option);
for ($i = 0 ; $i<$len ; ++$i )
{
if ( $i == 0 )
{
if ( $option[$i] == "'" ) $option_tmp .= "\\";;
}
else
{
if ( $option[$i] == "'" && $option[$i-1] != "\\")
{
$option_tmp .= "\\";
}
}
$option_tmp .= $option[$i];
//$option = str_replace("'","\\'",$option);
}
return $option_tmp;
}
function PrintErr($out)
{
$ret = "<table cellspasing=2 cellpadding=2 align=center style=\"border: 1px solid red\"><tr><td bgcolor=red>";
$ret .= "<font color=white><b>Error</b></font>";
$ret .= "</td></tr>";
$ret .= "<tr><td>";
$ret .= $out;
$ret .= "</td></tr></table>";
return $ret;
}
if ( !db_connect() )
exit();