我想我发现了一个再次出现的错误,但我不能完全确认它是否是。我们目前使用的是MongoPHP驱动程序的1.5.5版本。我使用以下步骤重新创建:
启动两个mongo服务器并将它们放入副本集中
加载连接到mongo和副本集的php
取下二级mongo服务器并启动备份
加载连接到mongo的php。
我得到一个'没有找到候选服务器',但大约每10次加载php页面的尝试中就有一次。重新启动apache解决了这个问题。所以对我来说感觉很相似:
PHP Mongo Error reading from socket
但它确实说这是固定的。我在登录时捕获到此错误:

Notice: PARSE INFO: Parsing mongodb://ny1-uutp-fdsa-31:27017,ny1-uutp-fdsa-32:27017 in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: PARSE INFO: - Found node: ny1-uutp-fdsa-31:27017 in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: PARSE INFO: - Found node: ny1-uutp-fdsa-32:27017 in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: PARSE INFO: - Connection type: MULTIPLE in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: PARSE INFO: - Found option 'replicaSet': 'ghood' in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: PARSE INFO: - Switching connection type: REPLSET in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: PARSE INFO: - Found option 'connectTimeoutMS': 120000 in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: PARSE WARN: - Replacing previously set value for 'connectTimeoutMS' (60000) in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: CON FINE: found connection ny1-uutp-fdsa-31:27017;ghood;.;4523 (looking for ny1-uutp-fdsa-31:27017;ghood;.;4523) in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: CON FINE: found connection ny1-uutp-fdsa-32:27017;ghood;.;4523 (looking for ny1-uutp-fdsa-32:27017;ghood;.;4523) in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: CON INFO: mongo_get_read_write_connection: finding a REPLSET connection (read) in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: CON FINE: found connection ny1-uutp-fdsa-31:27017;ghood;.;4523 (looking for ny1-uutp-fdsa-31:27017;ghood;.;4523) in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: CON INFO: is_ping: pinging ny1-uutp-fdsa-31:27017;ghood;.;4523 in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: CON FINE: No timeout changes for ny1-uutp-fdsa-31:27017;ghood;.;4523 in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: CON FINE: mongo_connection_destroy: Destroying connection object for ny1-uutp-fdsa-31:27017;ghood;.;4523 in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: CON FINE: mongo_connection_destroy: Closing socket for ny1-uutp-fdsa-31:27017;ghood;.;4523. in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: CON WARN: Couldn't connect to 'ny1-uutp-fdsa-31:27017': Remote server has closed the connection in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: CON FINE: found connection ny1-uutp-fdsa-32:27017;ghood;.;4523 (looking for ny1-uutp-fdsa-32:27017;ghood;.;4523) in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: CON INFO: is_ping: pinging ny1-uutp-fdsa-32:27017;ghood;.;4523 in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: CON FINE: No timeout changes for ny1-uutp-fdsa-32:27017;ghood;.;4523 in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: CON FINE: mongo_connection_destroy: Destroying connection object for ny1-uutp-fdsa-32:27017;ghood;.;4523 in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: CON FINE: mongo_connection_destroy: Closing socket for ny1-uutp-fdsa-32:27017;ghood;.;4523. in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: CON WARN: Couldn't connect to 'ny1-uutp-fdsa-32:27017': Remote server has closed the connection in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: CON FINE: discover_topology: checking ismaster for ny1-uutp-fdsa-31:27017;ghood;.;4523 in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: CON WARN: discover_topology: couldn't create a connection for ny1-uutp-fdsa-31:27017;ghood;.;4523 in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: CON FINE: discover_topology: checking ismaster for ny1-uutp-fdsa-32:27017;ghood;.;4523 in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: CON WARN: discover_topology: couldn't create a connection for ny1-uutp-fdsa-32:27017;ghood;.;4523 in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: REPLSET FINE: finding candidate servers in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: REPLSET FINE: - all servers in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: REPLSET FINE: - collect any in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: REPLSET FINE: filter_connections: adding connections: in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: REPLSET FINE: filter_connections: done in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: REPLSET FINE: limiting to servers with same replicaset name in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: REPLSET FINE: limiting to servers with same replicaset name: done in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: REPLSET FINE: limiting by credentials in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Notice: REPLSET FINE: limiting by credentials: done in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

Fatal error: Uncaught exception 'MongoConnectionException' with message 'No candidate servers found' in /ext1/FIDMGR/sdtk/htdocs/rick.php:8 Stack trace: #0 /ext1/FIDMGR/sdtk/htdocs/rick.php(8): MongoClient->__construct('mongodb://ny1-u...', Array) #1 {main} thrown in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8

我用来调试的代码非常简单:
<?

MongoLog::setModule( MongoLog::ALL );
MongoLog::setLevel( MongoLog::ALL );

error_reporting( E_ALL );

$mongo = new MongoClient('mongodb://ny1-uutp-fdsa-31:27017,ny1-uutp-fdsa-32:27017',Array('replicaSet' => 'ghood', "connectTimeoutMS" => 120000));
$mongo->setReadPreference(MongoClient::RP_NEAREST);

$userColl = $mongo->user->users;

var_dump($mongo->getConnections);
var_dump($mongo->getReadPreference());

还有什么我可以查一下的吗?
我在这里碰到的是一个设置问题吗?

最佳答案

我注意到你的日志上写着Couldn't connect to 'ny1-uutp-fdsa-31:27017': Remote server has closed the connection,然后找到ny1-uutp-fdsa-32:27017。但是到服务器的连接也被关闭了。然后它试图找到一个新的主机,但无法连接到任何一个。所以,也许你的错误信息是正确的。当你认为你只关闭了一台服务器时,你是不是意外地关闭了这两台服务器?
尝试在php.ini中将mongo.is_master_interval降低到1或2秒。这将有助于php更快地寻找新的主服务器。默认值为15秒。
另外,当php驱动程序无法连接到服务器时,它会将其列入黑名单,并且在mongo.ping_interval过期之前不会尝试再次连接。因此,如果您关闭一个服务器,然后将其重新启动,则需要很长时间,直到php再次尝试连接它。默认值为5秒。
我看到你的连接超时是120000,也就是两分钟。这似乎也太长了。正如我在对您的问题的评论中指出的,我也遇到了类似的问题,但是我的连接超时只有100毫秒,这可能太短了。也许可以试试5000。
因此,调整ping_间隔并将master_间隔调整为几秒,然后重新启动apache。同时更改代码以缩短连接超时时间。确保你只取下并带回一台服务器。然后等待时间间隔和超时的总和过去,看看问题是否仍然存在。如果是这样的话,我认为这可以保证在MongoDB上开一张罚单。我会让你知道,如果我看到的问题仍然发生后,提高我的连接超时。
我也读过你链接到的bug report。我发现mongolab发布的这些php mongodb驱动提示和技巧很有帮助:http://blog.mongolab.com/2014/05/mongodb-driver-tips-tricks-php/

关于php - '找不到候选服务器'mongo错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25507700/

10-16 13:01
查看更多