MongoDB Blacklisted Fatal Error

I saw this error a couple of times, and to fix it, I just restart my server.

Fatal error: thrown a "MongoConnectionException" exception with message 'Failed to connect to: localhost: 27017: Previous connection failed, server blacklisted /var/www/html/include/config.php:9 Stack trace: # 0 / var / www / html / include / config.php (9): MongoClient-> __construct ('mongodb: // local ...') # 1 /var/www/html/classes.php(3): include (' / var / www / html / i ... ') # 2 /var/www/html/myusers.php(8): include (' / var / www / html / c ... ') # 3 {main} thrown at /var/www/html/include/config.php on line 9

However, I can be at that time without seeing this ... How can I prevent a problem from occurring?

update: this happened again, and after a few minutes of waiting I had to reboot in order for the site to work again.

+8
php mongodb
source share
3 answers

Since the version of MongoDB version is for PHP version 1.4, we will be a "black list" of servers for a minute if they cannot be contacted. This is so that we do not slam the server with connections, which can lead to a timeout. This is primarily done to make sure that in an environment with replicas, we can still use only one of the hosts, but, of course, if you have only one machine, this is a little more complicated.

If you use MongoLog, you can very easily determine what is happening under the hood:

MongoLog::setModule(MongoLog::ALL); MongoLog::setLevel(MongoLog::ALL); MongoLog::setCallback('print_mongo_log'); function print_mongo_log($a, $b, $c) { echo $c, "\n"; } 

This will display everything the driver is trying to do. It would be interesting to see the dump first , when something goes wrong, and also at one time it is "stuck" in the black list.

The above warning will disappear after 60 seconds or when you reboot your web server software (or you are using PHP-FPM). If you think this explanation is incorrect, write a bug / function request at http://jira.mongodb.org/browse/PHP

+14
source share

This seems to be a problem caused by an error in the MongoDB PHP driver. Check if you are using version 1.4.0, if so, upgrade it to a newer version and the error should be fixed.

+1
source share

It seems that mongo processes the connections on its own, you should not use a closed connection in your code, if you want to use the persistence mongo connection, I solved this problem by removing the php script connection from mongo as follows:

DO NOT USE CLOSE ..............

 $client = new MongoClient("mongodb://127.0.0.1:27017"); //close mongo connection $client->close(); 

Hope to be helpful.

0
source share

All Articles