如何跟踪建立/关闭 mysql 连接的开销

发布于 2024-09-28 08:39:30 字数 53 浏览 0 评论 0原文

我正在尝试确定是否应该使用持久连接。如何跟踪 PHP 中建立/关闭 mysql 连接的开销?

I'm trying to determine if I should be using persistent connections or not. How can I track the overhead of establishing/closing mysql connections in PHP?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独享拥抱 2024-10-05 08:39:30

您应该阅读此 http://www.php.net/manual/en /features.persistent-connections.php

持久连接对于 PHP 来说可能非常糟糕,因为 PHP 本身在其典型设置中不是持久的。最终发生的情况是 Apache 进程结束保持数据库连接打开,但未使用。所以你最终会有很多很多的数据库连接什么都不做。通常,您最终会达到为 mysql 设置的最大连接数。

基本上,除非您的 Web 服务器和数据库之间的连接非常慢(而且不应该如此),否则不要使用持久连接。听起来不合逻辑。

You should read this http://www.php.net/manual/en/features.persistent-connections.php

Persistent connections can be very bad with PHP since PHP itself is not persistent in it's typical setup. What ends up happening is that the Apache processes ending keeping the DB connections open, but not used. So you end up having lots and lots of DB connections doing nothing. Usually you end up hitting the max connections you set for mysql.

Basically, unless the connection between your web server and db is very slow (and it shouldn't be), don't use persistent connections. As illogical as it sounds.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文