PHP MySQLi与SSL的持久连接

时间:2011-07-25 20:58:05

标签: php ssl mysqli persistent

我在通过ssl配置持久MySQLi连接时遇到问题。任何建议表示赞赏。

没有持久连接:

$flags = MYSQLI_CLIENT_SSL;
$link = new mysqli();
$link->ssl_set(null, null, null, null, "RC4-MD5");
if ($link->real_connect($host, $user, $pass, $db, $port, null, $flags)) {
    $r = $link->query("SHOW STATUS LIKE 'Ssl_cipher'");
    var_dump($r->fetch_row());
}

输出

array(2) {
   [0]=> string(10) "Ssl_cipher"
   [1]=> string(18) "RC4-MD5"
}

持久连接:

$flags = MYSQLI_CLIENT_SSL;
$link = new mysqli();
$link->ssl_set(null, null, null, null, "RC4-MD5");
if ($link->real_connect('p:' . $host, $user, $pass, $db, $port, null, $flags)) {
    $r = $link->query("SHOW STATUS LIKE 'Ssl_cipher'");
    var_dump($r->fetch_row());
}

输出

array(2) {
   [0]=> string(10) "Ssl_cipher"
   [1]=> string(0) ""
}

更新:我认为这是一个php bug https://bugs.php.net/bug.php?id=55283 - 基本上ssl_set()被忽略为持久连接,在我的情况下,由于服务器配置,这将连接降级为非ssl。

1 个答案:

答案 0 :(得分:0)

你必须先在real_connect之前运行mysqli :: ssl_set。

http://www.php.net/manual/en/mysqli.ssl-set.php

相关问题