@@ -321,6 +321,93 @@ Miscellaneous Configuration
321
321
| **MongoDB\\Client Example**: ``$uriOptions = ['srvMaxHosts' => 5];``
322
322
| **Connection URI Example**: ``srvMaxHosts=5``
323
323
324
+ Troubleshooting
325
+ ---------------
326
+
327
+ This section addresses issues related to MongoDB connection options.
328
+
329
+ Server Selection Errors
330
+ ~~~~~~~~~~~~~~~~~~~~~~~
331
+
332
+ The following code shows possible server selection error
333
+ messages that your application might generate:
334
+
335
+ .. code-block:: none
336
+ :copyable: false
337
+
338
+ No suitable servers found (`serverSelectionTryOnce` set):
339
+ [connection refused calling hello on 'a.example.com:27017']
340
+ [connection refused calling hello on 'b.example.com:27017']
341
+
342
+ No suitable servers found: `serverSelectionTimeoutMS` expired:
343
+ [socket timeout calling hello on 'example.com:27017']
344
+
345
+ No suitable servers found: `serverSelectionTimeoutMS` expired:
346
+ [connection timeout calling hello on 'a.example.com:27017']
347
+ [connection timeout calling hello on 'b.example.com:27017']
348
+ [TLS handshake failed: -9806 calling hello on 'c.example.com:27017']
349
+
350
+ No suitable servers found: `serverselectiontimeoutms` timed out:
351
+ [TLS handshake failed: certificate verify failed (64): IP address mismatch calling hello on 'a.example.com:27017']
352
+ [TLS handshake failed: certificate verify failed (64): IP address mismatch calling hello on 'b.example.com:27017']
353
+
354
+ The {+extension-short+} usually represents these errors as
355
+ :php:`MongoDB\Driver\Exception\ConnectionTimeoutException <mongodb-driver-exception-connectiontimeoutexception>`
356
+ exceptions. However, the exception messages originate from
357
+ ``libmongoc``, which is the underlying system library used by the extension. Since
358
+ these messages can take many forms, we recommend breaking down the structure of
359
+ the message so you can better diagnose errors in your application.
360
+
361
+ Messages typically start with "No suitable servers found". The next part of
362
+ the message indicates *how* server selection failed. The extension
363
+ avoids a server selection loop and makes a single attempt by default, according to
364
+ the ``serverSelectionTryOnce`` connection string option. If the extension is
365
+ configured to use a loop, a message that includes the phrase "serverSelectionTimeoutMS expired"
366
+ indicates that you exhausted its time limit.
367
+
368
+ The last component of the message tells us *why* server selection failed and
369
+ includes one or more errors directly from the topology scanner, which is the
370
+ service responsible for connecting to and monitoring each host. Any host that
371
+ previously experienced an error during monitoring will be included in this list. These
372
+ messages typically originate from low-level socket or TLS functions.
373
+
374
+ The following list describes the possible meanings of common phrases in the last error message
375
+ component:
376
+
377
+ - "Connection refused": The remote host might not be not listening on
378
+ the expected port.
379
+ - "Connection timeout": There might be a routing problem, a firewall error, or
380
+ a timeout due to latency.
381
+ - "Socket timeout": You likely established an initial connection that
382
+ was dropped or timed out due to latency.
383
+ - "TLS handshake failed": TLS or OCSP verification did not succeed, and you might
384
+ have misconfigured TLS certificates.
385
+
386
+ In the case of a connection failure, you can use the ``connect`` tool for
387
+ more troubleshooting information. This tool tries to connect to each host in a
388
+ connection string by using socket functions, and then attempts to interact with
389
+ data. If you used Composer to install the library, you can use the following command
390
+ to use the ``connect`` tool:
391
+
392
+ .. code-block:: none
393
+
394
+ php vendor/mongodb/mongodb/tools/connect.php <connection URI>
395
+
396
+ If the server you are connecting to does not accept connections, the output
397
+ resembles the following code:
398
+
399
+ .. code-block:: none
400
+
401
+ Looking up MongoDB at <connection URI>
402
+ Found 1 host(s) in the URI. Will attempt to connect to each.
403
+
404
+ Could not connect to <host>:<port>: Connection refused
405
+
406
+ .. note::
407
+
408
+ The tool supports only the ``mongodb://`` URI schema. Using the
409
+ ``mongodb+srv`` scheme is not supported.
410
+
324
411
API Documentation
325
412
-----------------
326
413
0 commit comments