简体   繁体   中英

PHP MySQLi persistent connections with SSL

I am having problem with configuring persistent MySQLi connections over ssl. Any suggestions are appreciated.

W/o persistent connections:

$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());
}

the the output is

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

With persistent connections:

$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());
}

the the output is

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

UPDATE: I believe this is a php bug https://bugs.php.net/bug.php?id=55283 - basically ssl_set() is ignored for persistent connections and in my case due to server config this downgraded the connection to be non-ssl.

You have to first run mysqli::ssl_set before real_connect.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM