@@ -100,50 +100,56 @@ for the correct environment.
100
100
The aforementioned ``detect-extension`` script can also be used to determine the
101
101
appropriate DLL for your PHP environment.
102
102
103
-
104
103
Connection Handling and Persistence
105
104
-----------------------------------
106
105
107
- Connections to the MongoDB deployment are handled entirely by libmongoc and the
108
- :php:`mongodb extension <mongodb>`. When a :phpclass:`MongoDB\Client` is
109
- constructed , the |php- library| creates a
110
- :php:`MongoDB\Driver\Manager <class.mongodb-driver-manager>` using the
106
+ Connections to the MongoDB deployment are handled by the ``libmongoc``
107
+ library and the :php:`{+ extension-short+} <mongodb>`. When you construct
108
+ a :phpclass:`MongoDB\Client` instance , the {+ library-short+} creates a
109
+ :php:`MongoDB\Driver\Manager <class.mongodb-driver-manager>` instance by using the
111
110
same connection string and options. The extension also uses those constructor
112
- arguments to derive a hash key for persistent libmongoc clients. If a libmongoc
113
- client was previously persisted with a key, it will be reused; otherwise, a new
114
- libmongoc client will be created and persisted for the lifetime of the PHP
115
- worker process. This process is described in more detail in the
116
- :php:`extension documentation <manual/en/mongodb.connection-handling.php>`.
117
-
118
- Each libmongoc client maintains its own connections to the MongoDB deployment
119
- and a view of its topology. When a persistent libmongoc client is reused, the
120
- PHP driver can avoid the overhead of establishing new connections and
111
+ arguments to derive a hash key for persistent ``libmongoc`` clients. If
112
+ you previously persisted a ``libmongoc`` client by using a key, it is
113
+ reused. Otherwise, a new ``libmongoc`` client is created and persisted
114
+ for the lifetime of the PHP worker process. You can learn more about
115
+ this process in the :php:`{+extension-short+} documentation
116
+ <manual/en/mongodb.connection-handling.php>`.
117
+
118
+ Each ``libmongoc`` client maintains its own connections to the MongoDB deployment
119
+ and a view of its topology. When you reuse a persistent ``libmongoc`` client, the
120
+ {+library-short+} can avoid the overhead of establishing new connections and
121
121
rediscovering the topology. This approach generally improves performance and is
122
- therefore the driver's default behavior.
122
+ the driver's default behavior.
123
123
124
- Persistent libmongoc clients are not freed until the PHP worker process
125
- terminates . This means that connections to a MongoDB deployment may remain open
126
- long after a ``MongoDB\Driver\Manager`` object goes out of scope. While this is
124
+ Persistent `` libmongoc`` clients are not freed until the PHP worker process
125
+ ends . This means that connections to a MongoDB deployment might remain open
126
+ after a ``MongoDB\Driver\Manager`` object goes out of scope. While this is
127
127
typically not an issue for applications that connect to one MongoDB deployment,
128
- it could be problematic in some situations. Consider the following cases:
128
+ it might be problematic in some situations, which are described in the
129
+ following list:
129
130
130
- - PHP-FPM is configured with ``pm.max_requests=0`` ( workers never respawn) and a
131
+ - PHP-FPM is configured with ``pm.max_requests=0``, so that workers never respawn, and a
131
132
PHP application is deployed many times with small changes to its MongoDB
132
- connection string or options. This could lead to an accumulation of libmongoc
133
- client objects within each worker process.
134
- - An application occasionally connects to a separate MongoDB deployment in some
135
- backend component where request latency is not paramount.
133
+ connection string or options. This could lead to an accumulation of ``libmongoc``
134
+ client objects in each worker process.
135
+
136
+ - An application occasionally connects to a separate MongoDB deployment in a
137
+ backend component where request latency is not the most important aspect.
136
138
137
139
In the first case, restarting PHP-FPM as part of the application deployment
138
- allows the application to relinquish any unused libmongoc clients and still use
140
+ allows the application to release any unused `` libmongoc`` clients and still use
139
141
a persistent client for the latest connection string.
140
142
141
- The second case warrants a different solution. Specifying ``true`` for the
142
- ``disableClientPersistence`` driver option will instruct the PHP driver to
143
- create a new libmongoc client and ensure it is freed when the corresponding
143
+ The second case requires a different solution. Specifying ``true`` for the
144
+ ``disableClientPersistence`` driver option instructs the {+library-short+} to
145
+ create a new `` libmongoc`` client and ensure it is freed when the corresponding
144
146
``MongoDB\Driver\Manager`` goes out of scope.
145
147
148
+ The following code demonstrates how to set the
149
+ ``disableClientPersistence`` option to ``true`` when creating a client:
150
+
146
151
.. code-block:: php
152
+ :emphasize-lines: 6
147
153
148
154
<?php
149
155
@@ -153,10 +159,10 @@ create a new libmongoc client and ensure it is freed when the corresponding
153
159
driverOptions: ['disableClientPersistence' => true],
154
160
);
155
161
156
- Use the ``disableClientPersistence`` driver option sparingly, as opting out of
157
- client persistence will require more time to establish connections to the
158
- MongoDB deployment and discover its topology.
159
-
162
+ Use the ``disableClientPersistence`` driver option after careful
163
+ consideration, because opting out of client persistence requires more
164
+ time to establish connections to the MongoDB deployment and discover its
165
+ topology.
160
166
161
167
Server Selection Failures
162
168
-------------------------
0 commit comments