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