ze_lin_huang
2017-11-12 11:27php连接远程mongodb查询很慢
php连接远程mongodb查询很慢,查询数据量大概6000条,大概用了4秒。
求大神请教下,怎么连接远程monogdb,是代码问题还是需要配置什么?
$mongo = new MongoClient('mongodb://xx.xx.xx.xx:27017/test');
$filter['every_day'] = array('$gte' => "2017-01-01", '$lte' => "2017-09-30");
$cursor = $mongo->selectCollection('test', 'test')->find($filter);
$data = [];
$starttime = explode(' ', microtime());
foreach ($cursor as $id => $value) {
$data[] = $value;
}
$endtime = explode(' ', microtime());
$thistime = $endtime[0] + $endtime[1] - ($starttime[0] + $starttime[1]);
$thistime = round($thistime, 3);
echo "执行耗时:" . $thistime . " 秒。";
- 点赞
- 回答
- 收藏
- 复制链接分享
1条回答
为你推荐
- 通过PHP连接到MongoDB时出现最大限制大小错误
- mongodb
- php
- 1个回答
- 如何将mongoDB shell查询转换为php
- mongodb
- php
- 1个回答
- PHP中的MongoDB聚合
- mongodb
- php
- 1个回答
- PHP MongoDB获取统计信息
- mongodb
- php
- 1个回答
- PHP mongodb总和查询
- mongodb
- mysql
- php
- sum
- 3个回答
换一换