pg.ddx.io pgsql-php@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Melvyn Sopacua <mdev@idg.nl>
To: PostgreSQL Adminlist <pgsql-admin@postgresql.org>
Subject: Re: Script Hangs on
Date: Wed, 06 Jun 2001 14:42:45 +0200
Message-ID: <5.0.2.1.2.20010606134350.02aa3ca0@tmp.idg.nl> (raw )
In-Reply-To: <Pine.LNX.4.21.0106061516260.31520-100000@webster.conprojan .com.au >
References: <3B1DB7BF.534EBA89@kikakuya.com >
At 07:21 6-6-01, you wrote:
> $dbconn1 = @pg_connect ("host=$dbhost dbname=$dbname user=$dbuser
>password=$dbpasswd");
>
>Edit /usr/local/lib/php.ini and make sure persistent connections is
>turned off.
This will work, as long as the machine is up, but pgsql isn't. However, if the
machine isn't up, the timeout is tremendous.
Use this, or view source online at
http://melvyn.idg.nl/phpsources/db_connect_plus.phps :
<?
//These are included from the global application configuration
$cfg_vars['data_root']='/cgi-data';
$cfg_vars['appname']='your app';
$cfg_vars['appemail']='your app email sender';
$cfg_vars['pg_admin']='pgadmin@domain.com';
function db_connect_plus()
{
global $cfg_vars;
$primary='your_ip_primary';
$secondary='your_ip_secondary';
$port='your_port';
$username='username';
$password='blabla';
$timeout=10;
$now=time();
$skipcheck=10;
$primcheck=$cfg_vars[data_root].'/primary_down';
$seccheck=$cfg_vars[data_root].'/secondary_down';
$appname=$cfg_vars['appname'];
$appemail=$cfg_vars['appemail'];
$connect='pg_connect'; // Choose your connection type (db type +
persistent/not persistent) here.
if(file_exists($primcheck))
{
$lastmod=filemtime($primcheck);
if($now - $lastmod > $skipcheck)
{
if($sp=fsockopen($primary, $port, &$errno,
&$errstr, $timeout))
{
fclose($sp);
unlink($primcheck);
$is_mailed=mail($cfg_vars[pg_admin],
"Primary $primary back up.", date("l dS of F Y h:i:s A", $now), "From:
$appname <$appemail>");
return $connect($primary, $username,
$password);
}
else
{
unlink($primcheck);
touch($primcheck);
mail($cfg_vars[pg_admin], "Primary
$primary down", "$errno\n$errstr", "From: $appname <$appemail>\nX-Priority:
1 (Highest)\nX-MSMail-Priority: High");
}
}
}
else
{
if($sp=fsockopen($primary, $port, &$errno, &$errstr,
$timeout))
{
fclose($sp);
return $connect($primary, $username, $password);
}
else
{
touch($primcheck);
mail($cfg_vars[pg_admin], "Primary $primary down",
"$errno\n$errstr", "From: $appname <$appemail>\nX-Priority: 1
(Highest)\nX-MSMail-Priority: High");
}
}
//If we get this far, the primary is down, so do the secondary.
if(file_exists($seccheck))
{
$lastmod=filemtime($seccheck);
if($now - $lastmod > $skipcheck)
{
if($sp=fsockopen($secondary, $port, &$errno,
&$errstr, $timeout))
{
fclose($sp);
unlink($seccheck);
mail($cfg_vars[pg_admin], "Secondary
$secondary back up.", date("l dS of F Y h:i:s A", $now), "From: $appname
<$appemail>");
return $connect($secondary, $username,
$password);
}
else
{
unlink($seccheck);
touch($seccheck);
mail($cfg_vars[pg_admin], "secondary
$secondary down", "$errno\n$errstr", "From: $appname
<$appemail>\nX-Priority: 1 (Highest)\nX-MSMail-Priority: High");
}
}
}
else
{
if($sp=fsockopen($secondary, $port, &$errno, &$errstr,
$timeout))
{
fclose($sp);
return $connect($secondary, $username, $password);
}
else
{
touch($seccheck);
mail($cfg_vars[pg_admin], "secondary $secondary
down", "$errno\n$errstr", "From: $appname <$appemail>");
}
}
//if we get this far, both are down!
return 0;
}
$cs=db_connect_plus();
if(!$cs)
{
die("Oh oh - 2 database servers down. And you think you're
redundant..");
}
?>
view thread (7+ messages)
Message-ID: <5.0.2.1.2.20010606134350.02aa3ca0@tmp.idg.nl>
Permalink: ../5.0.2.1.2.20010606134350.02aa3ca0@tmp.idg.nl/
Also on: postgresql.org/message-id/5.0.2.1.2.20010606134350.02aa3ca0@tmp.idg.nl
copy link · copy postgr.es
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-php@postgresql.org
Cc: mdev@idg.nl, pgsql-admin@postgresql.org
Subject: Re: Script Hangs on
In-Reply-To: <5.0.2.1.2.20010606134350.02aa3ca0@tmp.idg.nl>
References: <3B1DB7BF.534EBA89@kikakuya.com> <5.0.2.1.2.20010606134350.02aa3ca0@tmp.idg.nl>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox