Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2024-10-08 12:12:38

Adams
Plugin Author
Registered: 2024-08-30
Posts: 38

db unavailable error

This morning, when I tried to open the browser and point to the localhost TXP app, I got “Database unavailable.” I really don’t like to touch any core code to add or change anything for easy maintenance and upgrade in the future. But it will be nice to add more flexibility, for example, add option to include customdberror.php (or something like this) on function db_down() (txplib_db.php); in this case, the user can customize the error or even send an email when db is down (in shared hosting, DB issues are very common). I get error every few weeks when the server gets very busy.

Offline

#2 2024-10-08 14:58:48

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,444
Website GitHub

Re: db unavailable error

That is strange. Is your server fairly heavily loaded? Textpattern has a very modest footprint so it’s very rare to see the database unable to make a connection.

If you think it would be beneficial for a database_down() routine of some description then by all means submit a pull request on GitHub. It is a shame that at that point, we have no ability for plugins to play because they rely on a database connection before they can be loaded. But if there could be some well-known file somewhere that can be triggered in such situations then it might be a nice thing to have.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2024-10-08 18:15:16

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,254
GitHub

Re: db unavailable error

Adams wrote #337975:

I get error every few weeks when the server gets very busy.

If it’s a busy server (that is to say, over-provisioned or under-resourced for its tenants) it’s likely the maximum number of connections has been reached / breached, which would throw that error. Consider moving to another host. As Bloke says, Textpattern has very light usage so it’s likely your noisy neighbours that are lowering the tone.

Last edited by gaekwad (2024-10-08 18:33:08)

Offline

#4 2024-10-08 18:32:07

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,254
GitHub

Re: db unavailable error

Thinking about this…a fallback index.html could be used if your web serving software (Apache, Nginx, Caddy etc) allows it.

Offline

#5 2024-10-09 13:53:34

Adams
Plugin Author
Registered: 2024-08-30
Posts: 38

Re: db unavailable error

Sorry if I wasn’t clear, the error was on my local computer (localhost), I tried to explain this kind issued happened to me many time in the past (with hostgator) years ago.
I meant to have something like this, if possible:

function db_down()
{


    global $DB;
    // 503 status might discourage search engines from indexing or caching the
    // error message.
    txp_status_header('503 Service Unavailable');
    if (is_object($DB)) {
        $error = txpspecialchars(mysqli_error($DB->link));
    } else {
        $error = '$DB object is not available.';
    }

 /*
Show-friendly HTML message telling the visitor and the search engine something more meaningful, like the site in maintenance mode, and send email; do what you like to do within the php file.
*/
	$db_errorfile = './db_error.php';
    if ( file_exists( $db_errorfile ) ) 
	{
        require_once($db_errorfile);
	    return;	
    } else

    return <<<eod
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="robots" content="noindex">
    <title>Database unavailable</title>
</head>
<body>
    <p>Database unavailable.</p>
    <!-- $error -->
</body>
</html>
eod;
}

I guess I have to add this on my end and add note when I upgrade to add it back.

Thank you

Offline

Board footer

Powered by FluxBB