Received: from bsdi.nyvlem.mine.nu (node123e0.a2000.nl [24.132.35.224]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f56CjHE01658 for ; Wed, 6 Jun 2001 08:45:17 -0400 (EDT) (envelope-from mdev@idg.nl) Received: from server.idg.nl (server.nyvlem.mine.nu [192.168.0.1]) by bsdi.nyvlem.mine.nu (8.9.3/8.9.3) with ESMTP id OAA03218 for ; Wed, 6 Jun 2001 14:46:29 +0200 (CEST) Message-Id: <5.0.2.1.2.20010606134350.02aa3ca0@tmp.idg.nl> X-Sender: mdev@tmp.idg.nl X-Mailer: QUALCOMM Windows Eudora Version 5.0.2 Date: Wed, 06 Jun 2001 14:42:45 +0200 To: PostgreSQL Adminlist From: Melvyn Sopacua Subject: Re: Script Hangs on In-Reply-To: References: <3B1DB7BF.534EBA89@kikakuya.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Archive-Number: 200106/40 X-Sequence-Number: 1578 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: $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.."); } ?>