duanchuiwen6694 2013-09-19 22:34
浏览 79
已采纳

PHP Mongos驱动程序如何确定要连接的服务器

Say you have multiple Mongo shards in a production environment, so each of them are replica sets. You have three different Mongos instances running for connecting to these replica sets, so you're doing something like this:

new MongoClient("mongodb://mongos1.example.com:27017,mongos2.example.com:27017,mongos3.example.com:27017");

What scheme does the PHP Mongos driver use to determine which of these it's going to connect to? Doing a search for this, I've been able to find relatively little information, and the few things I have come across tend to contradict each other, some saying it picks the first one to respond, and others saying it picks the first one you enter in your code.

Does anyone know?

This is for PHP 1.3.4.

  • 写回答

1条回答 默认 最新

  • dssqq64884 2013-09-19 23:43
    关注

    As Sammaye stated, the MongoClient connects to the "nearest" mongos first, where "nearest" is determined by latency. If you're interested, you can take a look at manager.c and read_preference.c in the php driver.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献