pconnect是可复用的,应该不会出现你说的现象。

解决方案 »

  1.   

    我平时用show processlist看, 都不超过40个, 不知那晚为什么100个不够用, 会不会是某个php有问题? 
    我用'netstat -anp'看到很多TIME_WAIT的connections, 这是合故?
      

  2.   

    pconnect的过程应该是这样的,当连接到数据库,首先寻找是否存在一个持续连接与当前连接同服务器、用户名和密码,如果有则把当前连接的句柄返回。也就是说可以给不同的用户请求使用同一数据库连接。不过,持续连接不会因为脚本程序的结束而关闭,而且也不能用mysql_close()来关闭,所以就必须调整配置文件中的max connections。mysql_pconnect() 和 mysql_connect() 的区别就在于前者的效率更高速度更快。
      

  3.   

    但为什么所有ISP都建议关掉php.ini的pconnect功能? 如果我关掉了, 这些mysql_pconnect连接由谁来关闭?
      

  4.   

    pconnect使用户连接数据库的效率提高了,但带来的是服务器端资源的开销(想想看同时有250个连接到数据库),所以大多数ISP都会建议关掉pconnect。具体如何关闭idle的pconnect进程可以参看手册
      

  5.   

    很多用户是有不同的用户名和密码的 那么它们应该不属于一个persistent connection 如果不mysql_close的话,虚拟主机提供商 是不是就会出现那种情况阿  我想是那样的
    如下也是一段解释
    Be careful using mysql_pconnect. If you are hosting on an ISP, they may frown upon you using multiple persistant mysql connections as this consumes resources for a longer period of time. If your script crashes, your connection can stay open for long periods of time. If there is a loop involved, you could accidently eat up all the available connections. That might be considered abuse by an ISP and you could get in trouble. Try using mysql_connect first instead. 90% of the time, a non-persistant mysql_connect call will do the trick just fine.
      

  6.   

    我又查了一下php的文档, mysql_cononect不用close也会在php结束后自动关闭, 所以关掉persistent后所有原来的pconnect都会像connect那样自动关闭.
    同一个网站是可以共享persistent connection的, 因为多数情况都是同一个用户连同一个数据库, 而host通常是localhost.
    我还不知道怎么关掉存在的persistent connect, 不知道serveice mysqld restart可不可以.