2011-09-20 7 views
0

replicaSet을 사용하기위한 올바른 구문을 찾고 있습니다. PHP 페이지 http://php.net/manual/en/mongo.construct.php에 대한 설명서를 볼 수 있지만 다음에 무슨 일이 일어날 지 잘 모르겠습니다.MongoDB PHP ReplicaSet 올바른 구문

<?php 

// pass a comma-separated list of server names to the constructor 
$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 
$m2 = new Mongo("mongodb://ny1.example.com", array("replicaSet" => "myReplSet")); 

?> 

는 다음이 나는이 내가 CodeIgniter의 내에서 사용하고 기존 클래스의 전체 내용입니다

if($m1){ $mongo = $m1; }else{ $mongo = $m2; } 

같은 것을 작성해야합니다. 복제본 세트를 지원하도록 전환해야합니다.

<?php defined('BASEPATH') OR exit('No direct script access allowed'); 

class CI_Mongo extends Mongo 
{ 
    var $db; 

    function CI_Mongo() 
    { 
     // Fetch CodeIgniter instance 
     $ci = get_instance(); 
     // Load Mongo configuration file 
     $ci->load->config('mongo'); 

     // Fetch Mongo server and database configuration 
     $server = config_item('mongo_server'); 
     $dbname = config_item('mongo_dbname'); 

     // Initialise Mongo 
     if ($server) 
     { 
      parent::__construct($server); 
     } 
     else 
     { 
      parent::__construct(); 
     } 
     $this->db = $this->$dbname; 
    } 
} 
?> 

답변

0

아니요, 문서의 예를 이해하지 못했습니다. 이들은 replicaSet을 구성하는 두 가지 다른 방법이며, 하나만 사용해야합니다.

처음에는 여러 서버를 지정하고 Mongo는 처음 관리 할 때 replicaSet을 검색합니다.

두 번째 예는 단일 서버에서이를 감지하므로 더 간단 해 보입니다. 여기서는 하나의 서버가 다운 될 때까지 잘 작동합니다.

+0

와우 ... 완전히 설명서를 잘못 읽었습니다 :) 감사합니다! –

+0

최선을 다해도 발생합니다. –

관련 문제