PHP mongodb驱动程序是否检查副本集';每一个请求都是主人的要求

PHP mongodb驱动程序是否检查副本集';每一个请求都是主人的要求,php,mongodb,mongodb-php,nosql,Php,Mongodb,Mongodb Php,Nosql,对mongodb副本集的典型PHP调用 $m1 = new Mongo("mongodb://sf2.example.com,ny1.example.com", array("replicaSet" => "myReplSet")); 文件说: // you only need to pass a single seed, the driver will derive the full list and // find the master from this seed

对mongodb副本集的典型PHP调用

$m1 = new Mongo("mongodb://sf2.example.com,ny1.example.com", 
      array("replicaSet" => "myReplSet"));
文件说:

// you only need to pass a single seed, the driver will derive the full list and
// find the master from this seed
问题:

  • 那么,这是否意味着驱动程序将
    根据每个请求导出完整列表?或者他们会缓存它

  • 如果他们缓存它,在故障转移过程中会导致问题吗?当从属设备降级为辅助设备时,写入从属设备

  • 当驱动程序遇到写入错误时,是否会刷新服务器列表并重试写入

  • 回答您的问题:

    1) PHP驱动程序与大多数MongoDB驱动程序一样,一旦派生出连接信息,就会缓存它

    2) 在发生故障转移时,前主节点将断开与所有客户端的所有连接。下次驱动程序尝试读取或写入套接字时,将出现错误。如果驱动程序在操作时无法重新连接到新的主节点,它将抛出一个PHP MongoConnectionException异常

    3) 由应用程序捕获此异常并在引发此异常时重试


    参考资料:

    这一点很好,因此通常会对读/写操作执行重试。从网络上的大多数示例代码来看,他们似乎并不在意。。