我有一个关于 PDO 持久连接的问题。现在这可能不是一个实际问题,但我似乎找不到任何解决此行为的帖子。
我正在为我的 Web 应用程序以持久连接模式使用良好的旧 PDO。现在我正在通过 new PDO(...)
创建一个新连接。
当我运行此脚本时,将建立一个新连接 (C#1) 和一个 MySql 进程 (P#1) 来容纳持久连接。
因此,我再次运行脚本创建一个新的连接 (C#2) 并期望 C#2 使用上次连接的 P#1。每次我运行这个脚本时,都会出现一个新进程,而最后一个进程仍然存在(处于 sleep 模式)。
在我的生产服务器上,在任何给定时间都有来自 3 个不同用户的大约 350 个进程(处于 sleep 状态)(所有用户都从同一个 apache 服务器连接)。
问题:这种情况是否有效?
最佳答案
找到我的答案
They cause the child process to simply connect only once for its entire lifespan, instead of every time it processes a page that requires connecting to the SQL server. This means that for every child that opened a persistent connection will have its own open persistent connection to the server. For example, if you had 20 different child processes that ran a script that made a persistent connection to your SQL server, you'd have 20 different connections to the SQL server, one from each child.
http://php.net/manual/en/features.persistent-connections.php
关于php - 使用 PDO 持久连接时,MySql 进程似乎卡住了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25288765/