gpt4 book ai didi

PHP & mysqli : What is the difference between persistent connection and interactive?

转载 作者:搜寻专家 更新时间:2023-10-31 20:47:49 27 4
gpt4 key购买 nike

以下有什么区别:

// Persistent connection
$mysqli->real_connect("p:" . $host, $user, $pass, $db, null, null, 0);

// Interactive connection
$mysqli->real_connect($host, $user, $pass, $db, null, null, MYSQLI_CLIENT_INTERACTIVE);

甚至这个……

// Interactive AND persistent
$mysqli->real_connect("p:" . $host, $user, $pass, $db, null, null, MYSQLI_CLIENT_INTERACTIVE);

最佳答案

只是我对文档的解释...

持久连接无限期地保持打开状态。非持久连接不是。

mysql_pconnect()文档比 real_connect() 文档更清晰:

mysql_pconnect() acts very much like mysql_connect() with two major differences.

First, when connecting, the function would first try to find a (persistent) link that's already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.

Second, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use ( mysql_close() will not close links established by mysql_pconnect()).

This type of link is therefore called 'persistent'.

关于 MYSQLI_CLIENT_INTERACTIVE :

MYSQLI_CLIENT_INTERACTIVE

Allow interactive_timeout seconds (instead of wait_timeout seconds) of inactivity before closing the connection. The client's session wait_timeout variable will be set to the value of the session interactive_timeout variable.

通常,非持久连接在 wait_timeout 变量指定的秒数后关闭。使用此标志,它们会在 interactive_timeout 变量指定的秒数后关闭。

根据我的解释,这意味着 MYSQLI_CLIENT_INTERACTIVE 不会更改持久 连接的行为。

关于PHP & mysqli : What is the difference between persistent connection and interactive?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11384121/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com