php - 使用 PDO 持久连接时,MySql 进程似乎卡住了

标签 php mysql pdo persistent-connection

我有一个关于 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/

相关文章:

php - 图像未保存在文件夹中

mysql - PDO 与 Laravel 的绑定(bind)错误

php - fatal error : [] operator not supported for strings multiple delete using PDO

php - php中如何将表中的数据从一个函数传递到另一个函数

php - PHP和MySQL:mysqli_num_rows()错误。怎么了?

c# - 无效的对象名称 SQL 选择

mysql - 为了 Heroku,从 MySQL 切换到 PostgreSQL for Ruby on Rails

php - LIMIT 使用偏移误差

php - PHP 中的可变变量允许使用非法变量名吗?

PHP 错误包装器?