How do I disable ibase_connect?

I am trying to implement a timeout when connecting to Firebird 2.5 db.

This is for a script that connects to 150+ servers. My goal is too unfortunate to server and move on to the next one to keep the script running.

Normal script execution time is 30 seconds, but if one server goes down it goes up to 300 seconds. I am using the ibase extension on PHP 7.

Any advice?

Thanks in advance.

+3


source to share


1 answer


The connection timeout parameter exists on the server side for sure, on the client you can try setting it in firebird.conf How about a test if the port is open before connecting?

<?php

function con_test($i, $p) {
    $f = @fsockopen($i, $p, $errno, $errstr, 0.1);
        if (!$f) {
            return false;
        } 
        else {
            fclose($f);
            return true;
        }
}   


$host[] = ['ip'=>'192.168.52.97','port' => '3050', 'alias' => 'test'];
$host[] = ['ip'=>'192.168.52.96','port' => '3050', 'alias' => 'test'];

$username='sysdba';
$password = 'masterkey';

foreach ($host as $k=>$v)
 {
 if (con_test($v['ip'],$v['port'])) { 

    $host = $v['ip'].'/'.$v['port'].':'.$v['alias'];
    $dbh = ibase_connect($host, $username, $password);
    $stmt = 'SELECT \'test\' as test FROM rdb$database';
    $sth = ibase_query($dbh, $stmt);

    while ($row = ibase_fetch_object($sth)) {
    echo $row->TEST, PHP_EOL;
    }
    ibase_free_result($sth);
    ibase_close($dbh);
} 
else  {
    echo 'Cannot connect to '.$v['ip'].':'.$v['port'].PHP_EOL;
}                                        

      



}

+1


source







All Articles