Skip to content

Commit da7b1e4

Browse files
committed
Docs edits
1 parent edc759a commit da7b1e4

File tree

1 file changed

+38
-32
lines changed

1 file changed

+38
-32
lines changed

source/faq.txt

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -101,50 +101,56 @@ for the correct environment.
101101
The aforementioned ``detect-extension`` script can also be used to determine the
102102
appropriate DLL for your PHP environment.
103103

104-
105104
Connection Handling and Persistence
106105
-----------------------------------
107106

108-
Connections to the MongoDB deployment are handled entirely by libmongoc and the
109-
:php:`mongodb extension <mongodb>`. When a :phpclass:`MongoDB\Client` is
110-
constructed, the |php-library| creates a
111-
:php:`MongoDB\Driver\Manager <class.mongodb-driver-manager>` using the
107+
Connections to the MongoDB deployment are handled by the ``libmongoc``
108+
library and the :php:`{+extension-short+} <mongodb>`. When you construct
109+
a :phpclass:`MongoDB\Client` instance, the {+library-short+} creates a
110+
:php:`MongoDB\Driver\Manager <class.mongodb-driver-manager>` instance by using the
112111
same connection string and options. The extension also uses those constructor
113-
arguments to derive a hash key for persistent libmongoc clients. If a libmongoc
114-
client was previously persisted with a key, it will be reused; otherwise, a new
115-
libmongoc client will be created and persisted for the lifetime of the PHP
116-
worker process. This process is described in more detail in the
117-
:php:`extension documentation <manual/en/mongodb.connection-handling.php>`.
118-
119-
Each libmongoc client maintains its own connections to the MongoDB deployment
120-
and a view of its topology. When a persistent libmongoc client is reused, the
121-
PHP driver can avoid the overhead of establishing new connections and
112+
arguments to derive a hash key for persistent ``libmongoc`` clients. If
113+
you previously persisted a ``libmongoc`` client by using a key, it is
114+
reused. Otherwise, a new ``libmongoc`` client is created and persisted
115+
for the lifetime of the PHP worker process. You can learn more about
116+
this process in the :php:`{+extension-short+} documentation
117+
<manual/en/mongodb.connection-handling.php>`.
118+
119+
Each ``libmongoc`` client maintains its own connections to the MongoDB deployment
120+
and a view of its topology. When you reuse a persistent ``libmongoc`` client, the
121+
{+library-short+} can avoid the overhead of establishing new connections and
122122
rediscovering the topology. This approach generally improves performance and is
123-
therefore the driver's default behavior.
123+
the driver's default behavior.
124124

125-
Persistent libmongoc clients are not freed until the PHP worker process
126-
terminates. This means that connections to a MongoDB deployment may remain open
127-
long after a ``MongoDB\Driver\Manager`` object goes out of scope. While this is
125+
Persistent ``libmongoc`` clients are not freed until the PHP worker process
126+
ends. This means that connections to a MongoDB deployment might remain open
127+
after a ``MongoDB\Driver\Manager`` object goes out of scope. While this is
128128
typically not an issue for applications that connect to one MongoDB deployment,
129-
it could be problematic in some situations. Consider the following cases:
129+
it might be problematic in some situations, which are described in the
130+
following list:
130131

131-
- PHP-FPM is configured with ``pm.max_requests=0`` (workers never respawn) and a
132+
- PHP-FPM is configured with ``pm.max_requests=0``, so that workers never respawn, and a
132133
PHP application is deployed many times with small changes to its MongoDB
133-
connection string or options. This could lead to an accumulation of libmongoc
134-
client objects within each worker process.
135-
- An application occasionally connects to a separate MongoDB deployment in some
136-
backend component where request latency is not paramount.
134+
connection string or options. This could lead to an accumulation of ``libmongoc``
135+
client objects in each worker process.
136+
137+
- An application occasionally connects to a separate MongoDB deployment in a
138+
backend component where request latency is not the most important aspect.
137139

138140
In the first case, restarting PHP-FPM as part of the application deployment
139-
allows the application to relinquish any unused libmongoc clients and still use
141+
allows the application to release any unused ``libmongoc`` clients and still use
140142
a persistent client for the latest connection string.
141143

142-
The second case warrants a different solution. Specifying ``true`` for the
143-
``disableClientPersistence`` driver option will instruct the PHP driver to
144-
create a new libmongoc client and ensure it is freed when the corresponding
144+
The second case requires a different solution. Specifying ``true`` for the
145+
``disableClientPersistence`` driver option instructs the {+library-short+} to
146+
create a new ``libmongoc`` client and ensure it is freed when the corresponding
145147
``MongoDB\Driver\Manager`` goes out of scope.
146148

149+
The following code demonstrates how to set the
150+
``disableClientPersistence`` option to ``true`` when creating a client:
151+
147152
.. code-block:: php
153+
:emphasize-lines: 6
148154

149155
<?php
150156

@@ -154,10 +160,10 @@ create a new libmongoc client and ensure it is freed when the corresponding
154160
driverOptions: ['disableClientPersistence' => true],
155161
);
156162

157-
Use the ``disableClientPersistence`` driver option sparingly, as opting out of
158-
client persistence will require more time to establish connections to the
159-
MongoDB deployment and discover its topology.
160-
163+
Use the ``disableClientPersistence`` driver option after careful
164+
consideration, because opting out of client persistence requires more
165+
time to establish connections to the MongoDB deployment and discover its
166+
topology.
161167

162168
Server Selection Failures
163169
-------------------------

0 commit comments

Comments
 (0)