php mysql 持久连接_PHP MySQL连接持久性
從我閱讀文檔和評論,我看到:
mysql_pconnect上的文檔(不建議使用的方法)
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()).
并對該頁面發表評論
Persistent connections work well for CGI PHP managed by fastCGI, contrary to the suggestion above that they only work for the module version. That’s because fastCGI keeps PHP processes running between requests. Persistent connections in this mode are easily made immune to connection limits too, because you can set PHP_FCGI_CHILDREN << mysql’s max_connections <<< Apache’s MaxClients. This also saves resources.
關于mysqli_connect的文檔(新方法)
Prepending host by p: opens a persistent connection. mysqli_change_user() is automatically called on connections opened from the connection pool.
mysqli_change_user的文檔:
Changes the user of the specified database connection and sets the current database.
所以我的理解如下:pconnect在腳本結束后保持連接打開但是進程(或者可能是進程組)仍處于活動狀態(例如在設置了FCGI的服務器中).一次只有一個腳本使用連接,當新腳本獲取該連接時,將更新用戶和數據庫.
因此,如果使用FCGI和持久連接,則可以減少打開的數據庫連接數,但同時運行的腳本將不會共享同一連接.關于選擇哪個數據庫,連接沒有問題.
總結
以上是生活随笔為你收集整理的php mysql 持久连接_PHP MySQL连接持久性的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Golang 学习笔记资源
- 下一篇: Golang 入门笔记(二)中