Skip to content

Commit c1e89c5

Browse files
committed
Docs edits
(cherry picked from commit da7b1e4)
1 parent 71f110a commit c1e89c5

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
@@ -100,50 +100,56 @@ for the correct environment.
100100
The aforementioned ``detect-extension`` script can also be used to determine the
101101
appropriate DLL for your PHP environment.
102102

103-
104103
Connection Handling and Persistence
105104
-----------------------------------
106105

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
111110
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
121121
rediscovering the topology. This approach generally improves performance and is
122-
therefore the driver's default behavior.
122+
the driver's default behavior.
123123

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
127127
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:
129130

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
131132
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.
136138

137139
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
139141
a persistent client for the latest connection string.
140142

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
144146
``MongoDB\Driver\Manager`` goes out of scope.
145147

148+
The following code demonstrates how to set the
149+
``disableClientPersistence`` option to ``true`` when creating a client:
150+
146151
.. code-block:: php
152+
:emphasize-lines: 6
147153

148154
<?php
149155

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

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.
160166

161167
Server Selection Failures
162168
-------------------------

0 commit comments

Comments
 (0)