After restart of the mongod service I get a connection error for every database when I try to connect with PHP:
Failed to connect to: localhost:27017: Remote server has closed the connection
500 Internal Server Error - MongoConnectionException
After one or two refeshes the connection works again. It doesn't mind if the connection is made immediately after restart or after some time.
MongoDB version: 2.6.4
PHP MongoDB driver version: 1.5.5
Configuration: PHP-FPM with Apache2
I think the persistent connecting of the old mongo instance is used, but I can't find out how to fix this. Is there any way to force the Mongo driver to start a new connection when the first one fails?
The answer is no. DB connections don't gracefully shut down when you exit (or crash).
Ensure Your MongoDB Instance is Running Compass must connect to a running MongoDB instance. Make sure you have installed MongoDB and have a running mongod process. You should also check that the port where your MongoDB instance is running matches the port you provide in the Compass connect dialog.
To allow remote connections, you must edit the MongoDB configuration file — /etc/mongod. conf — to additionally bind MongoDB to an IP address which can be reached by your trusted remote computer. This way, your MongoDB installation will be able to listen to connections made to your MongoDB server from remote machines.
Definition. A connection pool is a cache of open, ready-to-use database connections maintained by the driver. Your application can seamlessly get connections from the pool, perform operations, and return connections back to the pool. Connection pools are thread-safe.
The solution we now use is that we restart Apache after we restart MongoDB. Not the best solution, but it works :).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With