douzi1991 2013-06-11 15:22
浏览 38

在PHP中关闭外部连接(例如memcached,redis)是一个好习惯吗?

My Memcached server and Redis server are different from my web server, so that inside the PHP scripts I would have to make connections to these two external ip.

My concern is that, it would be better for my web server to keep its connections to the two memcached/redis servers. So that when new users request a php page, the web server does not need to connect to the memcached/redis again and again.

$redis = new Redis(); $redis -> close(); (or similarly with memcached and mysql)

I am unsure about what close actually means in this case. Does it mean close connection with the redis server for this particular php script execution? Given my previous concern, would calling close in fact hinder my performance?

  • 写回答

2条回答 默认 最新

  • douchun6108 2013-06-11 15:25
    关注

    Nothing really happens to "close" the actual connection from your server. This actually is more of a memory management issue within the application than a networking/infrastructure issue between servers. Consider the case where you have a running program that may instantiate an arbitrary number of objects. The close() method allows these objects to be destructed and garbage collected. If you were creating hundreds of instances without closing them as they're finished with, you'd end up with memory leaks in your application.

    评论

报告相同问题?

悬赏问题

  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。