No suitable servers found (`serverselectiontryonce` set): [Failed connecting to '115.28.161.44:27017': Connection timed out] php mongodb 异常

我 php mongodb 拓展使用的是  MongoDB driver 今天查询数据的时候 偶尔会提示,

No suitable servers found (`serverselectiontryonce` set): [Failed connecting to '115.28.161.44:27017': Connection timed out],

提示的答题意思是 超时

贴出我的解决方法:

        $id = I('post.id');
        $this->getassign_common_data();
        $info = D('BigdataMailCustomer')->where(['id' => $id])->find();
        $object_id = $info['object_id'];
        $coll = $info['coll'];
        $options_base = ['connectTimeoutMS' => 50000, 'socketTimeoutMS' => 50000];
        $manager = new \MongoDB\Driver\Manager(C('mongodb_auth_url'), $options_base);
        $id = new \MongoDB\BSON\ObjectId($object_id);
        $filter = ['_id' => $id];
        $options = [];
        $query = new \MongoDB\Driver\Query($filter, $options);
        $rows = $manager->executeQuery(C('default_db') . '.' . $coll, $query);
        $doc = [];
        foreach ($rows as $document) {
            $doc = $document;
        }
        $this->assign('d', $doc);
        $this->display('view');

添加配置选项 连接超时 选项

 

posted @ 2017-03-01 16:39  timelesszhuang  阅读(8793)  评论(0编辑  收藏  举报