PHP-854, Hannes Magnusson said that what is found on http://www.php.net/manual/en/class.mongoclient.php:
isn't the best way to connect and that something like:
should be used instead.
While I understand the technical reason behind this, I think it would be easier for PHP developers that this mechanism would be done by the PHP driver internally.
There is various possibilities for this:
- Implement auto reconnect, like with mysqli/mysqlnd extensions, possibly with an internal retry counter that is reset upon success.
- Implement a retry loop internally (while connecting), configurable with a setting like: mongo.connect_retries
The advantages are:
- PHP devs don't have to re-implement it every time
- PHP devs don't have to figure out why they get "Remote server has closed the connection" and that it's normal behavior
- Connection details/mgmt handled at the same level that persistence is. (=> driver level instead of user land)
- By implementing automatic re-connection, it would even be possible to have PHP applications that are more robust in case of network issues, especially with long time running scripts, like cronjobs, queuing solutions,... that migth use only at startup.