Script Hangs on 
Author Message
 Script Hangs on
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?

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://www.***.com/



Sun, 23 Nov 2003 13:15:21 GMT
 Script Hangs on

Quote:
> <?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;


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.",

        exit;
    }

Quote:
}
> 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.

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://www.postgresql.org/search.mpl



Sun, 23 Nov 2003 13:32:47 GMT
 Script Hangs on

Frist ,How in script could I Ping?
Second,from command line Ping also hangs.

Quote:

> > <?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.

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command



Sun, 23 Nov 2003 13:50:17 GMT
 Script Hangs on

Quote:
> <?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.

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://www.postgresql.org/search.mpl



Sun, 23 Nov 2003 14:11:18 GMT
 Script Hangs on

Quote:

>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';

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;

Quote:
}

$cs=db_connect_plus();
if(!$cs)
{
         die("Oh oh - 2 database servers down. And you think you're
redundant..");
Quote:
}

?>

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster



Sun, 23 Nov 2003 21:21:57 GMT
 
 [ 5 post ] 

 Relevant Pages 

1. ASP script hangs on ADO Open

2. SCRIPT HANGS UP ON "CREATE" COMMAND

3. Cursor script hangs in a loop

4. P7 script hangs as at job

5. Cursor script hangs in loop

6. Script hangs on

7. Cursor script hangs in loop

8. Problem with a script hanging


 
Powered by phpBB® Forum Software