bae吧 关注:1,300贴子:8,157
  • 3回复贴,共1

php 连接mongodb 闲置30秒后关闭,重新连接连接不上,求指教

只看楼主收藏回复

php 连接mongodb 闲置30秒后关闭,重新连接连接不上,调用5次后又能连接,求指教怎样能解决
Failed to connect to: mongo.duapp.com:8908: send_package: error reading from socket: The socket is closed


IP属地:上海1楼2014-10-11 10:57回复
    我也遇到过同样问题,解决方法https://duxiulong.duapp.com/blog/a-241213072.html


    IP属地:天津来自手机贴吧2楼2014-10-14 17:55
    回复
      $mongoClient=NULL;
      $mongoDB=NULL;
      try{
      $mongoClient = new MongoClient("mongodb://{$host}:{$port}");
      $mongoDB = $mongoClient->selectDB($dbname);
      $mongoDB->authenticate($user, $pwd);
      }catch(Exception $ex){
      $mongoClient = new MongoClient("mongodb://{$host}:{$port}");
      $mongoDB = $mongoClient->selectDB($dbname);
      $mongoDB->authenticate($user, $pwd);
      }
      /*这里写你的业务逻辑代码*/
      $mongoClient->close(); /*一定要记得close*/
      我是昨天要用bae的这个东西碰到的,研究了一晚上搞出来的,给分吧。


      IP属地:广东3楼2015-01-20 10:39
      收起回复