Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何超时ibase_连接?_Php_Firebird_Firebird2.5 - Fatal编程技术网

Php 如何超时ibase_连接?

Php 如何超时ibase_连接?,php,firebird,firebird2.5,Php,Firebird,Firebird2.5,我试图在连接firebird 2.5 db时实现超时 这适用于连接到150多台服务器的脚本。我的目标是使该服务器失效,并移动到下一个服务器,以保持脚本执行时间 正常的脚本执行时间是30秒,但如果一台服务器出现故障,则最多会引发300秒。 我正在PHP7上使用ibase扩展 有什么建议吗 提前感谢。连接超时选项确实存在于服务器端,在客户端,您可以尝试在firebird.conf中设置它 在连接之前测试端口是否打开如何 <?php function con_test($i, $p) {

我试图在连接firebird 2.5 db时实现超时

这适用于连接到150多台服务器的脚本。我的目标是使该服务器失效,并移动到下一个服务器,以保持脚本执行时间

正常的脚本执行时间是30秒,但如果一台服务器出现故障,则最多会引发300秒。 我正在PHP7上使用ibase扩展

有什么建议吗


提前感谢。

连接超时选项确实存在于服务器端,在客户端,您可以尝试在firebird.conf中设置它 在连接之前测试端口是否打开如何

<?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;
}                                        

有一个属性
isc\u dpb\u connect\u timeout
,但是1)我不确定如何使用
ibase\u connect
配置它,2)IIRC它只在连接到服务器后但在连接到数据库之前生效(这与IMHO的目的不符)。