是否应该每次都使用PDO :: ATTR_PERSISTENT? [英] Should PDO::ATTR_PERSISTENT be used every time?

查看:140
本文介绍了是否应该每次都使用PDO :: ATTR_PERSISTENT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用PDO与数据库建立连接时,是否应该每次都使用PDO属性PDO :: ATTR_PERSISTENT?它说这将为该用户创建一个持久连接,并且每次您请求数据库连接时都将抓住相同的连接,而不是重新建立一个新连接.为什么这不是默认值?有什么理由不使用它吗?

When establishing a connection to a database using PDO, should the PDO attribute PDO::ATTR_PERSISTENT be used every time? It says that this creates a persistant connection for that user, and will grab that same connection instead of re-establishing a new one each time you ask for a database connection. Why isn't this the default? Is there any reason not to use it?

推荐答案

持久连接的问题是MySQL可用的连接数量受到限制.如果出了什么问题并且该连接没有关闭,则服务器将长时间保持打开状态.如果服务器用尽了连接,则与之绑定的每个应用程序都将不可用,直到有人进行干预.

The issue with persistant connections is that the number of connections available to MySQL is limited. If something goes wrong and that connection isn't closed, the server is going to leave it open for a long time. If the server runs out of connections, then every single application tied to it is going to be unavailable until someone intervenes.

您可能会不时想到某些问题,在错误的情况下,资源过度使用的问题可能会泄漏到数月之内(如果没有引起注意),从而使您非常逐渐退化性能和系统利用率随时间的推移而增加(全无收益).

You can probably expect something to go wrong from time to time, and under the wrong circumstances the problem of resource over-usage can leak into months if not noticed, leaving you with a very gradual degrade in performance and increase in system utilization over time (all for no gain).

这是一篇可以帮助您的好文章.它着重于MySQL,但是大多数相同的想法可以在DBMS的各个方面得到概括.

Here is one good article that can help you. It focuses on MySQL, but most of the same thoughts can be generalized across the spectrum of DBMS's.

PHP持久连接有害吗?

这篇关于是否应该每次都使用PDO :: ATTR_PERSISTENT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆