Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.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 如何缩短MySQL连接超时故障切换场景_Php_Wordpress - Fatal编程技术网

Php 如何缩短MySQL连接超时故障切换场景

Php 如何缩短MySQL连接超时故障切换场景,php,wordpress,Php,Wordpress,我在Wordpress插件中有一个故障转移场景,如果生产数据库离线,我的web服务器上的PHP脚本会尝试连接到备份数据库 目前,回退时间似乎长达60秒。这是PHP的默认值吗?我如何将时间设置为10秒左右 下面是脚本的相关部分 try { $DBblue = new \PDO('mysql:host='.$samhost.';'.'dbname='.$DBblue, $samuser, $sampass); $DBgreen =

我在Wordpress插件中有一个故障转移场景,如果生产数据库离线,我的web服务器上的PHP脚本会尝试连接到备份数据库

目前,回退时间似乎长达60秒。这是PHP的默认值吗?我如何将时间设置为10秒左右

下面是脚本的相关部分

  try
        {
            $DBblue = new \PDO('mysql:host='.$samhost.';'.'dbname='.$DBblue, $samuser, $sampass);
            $DBgreen = new \PDO('mysql:host='.$samhost.';'.'dbname='.$DBgreen, $samuser, $sampass);
        }
        catch (\PDOException $pde)
        {
            // Fallback Database connection
            $althost = get_option('fallback_host');
            $altuser = get_option('fallback_user');
            $altpass = get_option('fallback_password');
            $DBblue = new \PDO('mysql:host='.$althost.';'.'dbname='.$DBblue, $altuser, $altpass);
            $DBgreen = new \PDO('mysql:host='.$althost.';'.'dbname='.$DBgreen, $altuser, $altpass);
        }
试试这个:

$DBblue = new \PDO('mysql:host='.$samhost.';'.'dbname='.$DBblue, $samuser, $sampass, array(
    PDO::ATTR_TIMEOUT => "10",
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
));
 $DBgreen = new \PDO('mysql:host='.$samhost.';'.'dbname='.$DBgreen, $samuser, $sampass, array(
    PDO::ATTR_TIMEOUT => "10",
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
));
PDO::ATTR_TIMEOUT=>“10”->>>将超时设置为10秒

PDO::ATTR_ERRMODE=>PDO::ERRMODE_异常->>>Throw异常


更多信息:

也许:我的场景是MySQL服务器没有响应,似乎断开了回退连接。在budgiecollective.com的“On Air”文本下有一个例子。我不得不记下更改。我检查了更新的insert的语法,没有发现任何错误。我能为您提供任何其他帮助信息吗?