pg.ddx.io pgsql-php@postgresql.org mailing list archive
help / color / mirror / Atom feedScript Hangs on
7+ messages / 4 participants
[nested] [flat]
* Script Hangs on
@ 2001-06-06 04:55 Ariunbold Gerelt-Od <gereltod@kikakuya.com>
0 siblings, 3 replies; 7+ messages in thread
From: Ariunbold Gerelt-Od @ 2001-06-06 04:55 UTC (permalink / raw)
To: pgsql-admin@postgresql.org
By Php scripts I am connecting to database SERVER:
<?php
$port=9939;
$host=\"210.111.1.10\";
pg=pg_connect($port,$host);
?>
But problem is if somebody suddenly switch off
the server(210.111.1.10), the script hangs on.
How would my script check that host is open before connecting?
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Script Hangs on
@ 2001-06-06 05:21 Grant <grant@conprojan.com.au>
parent: Ariunbold Gerelt-Od <gereltod@kikakuya.com>
2 siblings, 0 replies; 7+ messages in thread
From: Grant @ 2001-06-06 05:21 UTC (permalink / raw)
To: Ariunbold Gerelt-Od <gereltod@kikakuya.com>; +Cc: pgsql-admin@postgresql.org
> <?php
> $port=9939;
> $host=\"210.111.1.10\";
> pg=pg_connect($port,$host);
> ?>
Hehe, don't escape the quotes around your variables.
Here's a function I use to connect to the database.
$dbhost = '210.111.1.10';
$dbuser = 'postgres';
$dbpasswd = 'meep';
$dbname = 'your_db';
function establish_db_connection() {
global $dbhost;
global $dbuser;
global $dbpasswd;
global $dbname;
global $dbconn1;
global $admin_email;
$dbconn1 = @pg_connect ("host=$dbhost dbname=$dbname user=$dbuser
password=$dbpasswd");
if (!($dbconn1)) {
echo "<BR><CENTER>Could not establish database connection.
Administrators have been notified.</CENTER><BR>";
// mail("$admin_email", "$group database connectivity is down.",
"The database is currently down", "From: $group@$SERVER_NAME\n");
exit;
}
}
> But problem is if somebody suddenly switch off
> the server(210.111.1.10), the script hangs on.
> How would my script check that host is open before connecting?
Edit /usr/local/lib/php.ini and make sure persistent connections is
turned off.
Goodluck.
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Script Hangs on
@ 2001-06-06 05:31 Csaba Bobak <rendszergazdi@trendkft.hu>
parent: Ariunbold Gerelt-Od <gereltod@kikakuya.com>
2 siblings, 1 reply; 7+ messages in thread
From: Csaba Bobak @ 2001-06-06 05:31 UTC (permalink / raw)
To: Ariunbold Gerelt-Od <gereltod@kikakuya.com>; +Cc: pgsql-admin@postgresql.org
> <?php
> $port=9939;
> $host=\"210.111.1.10\";
> pg=pg_connect($port,$host);
> ?>
> But problem is if somebody suddenly switch off
> the server(210.111.1.10), the script hangs on.
> How would my script check that host is open before connecting?
A simple ping maybe? :-)
Csaba
__________
This message went through virus scan at Trend Ltd. which stated
the message was clean of viri appeared before 2001.05.24.
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Script Hangs on
@ 2001-06-06 05:39 Ariunbold Gerelt-Od <gereltod@kikakuya.com>
parent: Csaba Bobak <rendszergazdi@trendkft.hu>
0 siblings, 1 reply; 7+ messages in thread
From: Ariunbold Gerelt-Od @ 2001-06-06 05:39 UTC (permalink / raw)
To: pgsql-admin@postgresql.org
Frist ,How in script could I Ping?
Second,from command line Ping also hangs.
Csaba Bobak wrote:
> > <?php
> > $port=9939;
> > $host=\"210.111.1.10\";
> > pg=pg_connect($port,$host);
> > ?>
>
> > But problem is if somebody suddenly switch off
> > the server(210.111.1.10), the script hangs on.
> > How would my script check that host is open before connecting?
>
> A simple ping maybe? :-)
>
> Csaba
>
> __________
> This message went through virus scan at Trend Ltd. which stated
> the message was clean of viri appeared before 2001.05.24.
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: [ADMIN] Script Hangs on
@ 2001-06-06 05:53 Grant <grant@conprojan.com.au>
parent: Ariunbold Gerelt-Od <gereltod@kikakuya.com>
0 siblings, 1 reply; 7+ messages in thread
From: Grant @ 2001-06-06 05:53 UTC (permalink / raw)
To: Ariunbold Gerelt-Od <gereltod@kikakuya.com>; +Cc: pgsql-php
> Frist ,How in script could I Ping?
> Second,from command line Ping also hangs.
Don't ping. Let PHP control whether or not it can connect. It will
time out. The problem is you have persistent connections set in
your php.ini file.
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: [ADMIN] Script Hangs on
@ 2001-06-06 06:01 Ariunbold Gerelt-Od <gereltod@kikakuya.com>
parent: Grant <grant@conprojan.com.au>
0 siblings, 0 replies; 7+ messages in thread
From: Ariunbold Gerelt-Od @ 2001-06-06 06:01 UTC (permalink / raw)
To: Grant <grant@conprojan.com.au>; +Cc: pgsql-php
I don't think it depends of PHP configuration. Because what if my script
was written in Perl or else????.
Grant wrote:
> > Frist ,How in script could I Ping?
> > Second,from command line Ping also hangs.
>
> Don't ping. Let PHP control whether or not it can connect. It will
> time out. The problem is you have persistent connections set in
> your php.ini file.
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Script Hangs on
@ 2001-06-06 12:42 Melvyn Sopacua <mdev@idg.nl>
parent: Ariunbold Gerelt-Od <gereltod@kikakuya.com>
2 siblings, 0 replies; 7+ messages in thread
From: Melvyn Sopacua @ 2001-06-06 12:42 UTC (permalink / raw)
To: PostgreSQL Adminlist <pgsql-admin@postgresql.org>
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..");
}
?>
^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2001-06-06 12:42 UTC | newest]
Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-06-06 04:55 Script Hangs on Ariunbold Gerelt-Od <gereltod@kikakuya.com>
2001-06-06 05:21 ` Grant <grant@conprojan.com.au>
2001-06-06 05:31 ` Csaba Bobak <rendszergazdi@trendkft.hu>
2001-06-06 05:39 ` Ariunbold Gerelt-Od <gereltod@kikakuya.com>
2001-06-06 05:53 ` Grant <grant@conprojan.com.au>
2001-06-06 06:01 ` Ariunbold Gerelt-Od <gereltod@kikakuya.com>
2001-06-06 12:42 ` Melvyn Sopacua <mdev@idg.nl>
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