Closed nadiahareb closed 4 years ago
I most recently broke down the structure of the server selection error message in this thread, so I'd suggest reading that comment for a more detail explanation. In your case, the root error for failing to select a server is a "connection timeout" attempting to reach the server on 127.0.0.1:27017
. This could either mean that no mongod
process is listening on that host/port or that your PHP environment is not able to make an outgoing connection. Both of those would likely fall outside of the driver itself.
I'd suggest attempting to reproduce the error with the most minimal example, such as connecting and executing a ping
command. We have an example in the library docs that demonstrates how to do so. Two things to note with that example are:
MongoDB\Client
object explicitly (see: MongoDB\Client::__construct()
) instead of doing so with no arguments as we have in our examples (again, for conciseness).One other alternative is that you can attempt to connect to the mongod
host via the HTTP protocol. If you search this repository's issues for file_get_contents
you should come up with several old comments where I advised users to do this simply to verify that PHP is able to make an outgoing connection. https://github.com/mongodb/mongo-php-library/issues/372#issuecomment-306801722 is one such example.
thank you very much for your reply and for your time , in attempt to execute this : $database = (new \MongoDB\Client)->test;
$cursor = $database->command(['ping' => 1]);
var_dump($cursor->toArray()[0]);
i get this error
MongoDB\Driver\Exception\ConnectionTimeoutException: No suitable servers found (serverSelectionTryOnce
set): [connection timeout calling ismaster on '127.0.0.1:27017']
at n/a
in C:\xampp\htdocs\SSS\vendor\mongodb\mongodb\src\Database.php line 176
at MongoDB\Driver\Manager->selectServer(object(ReadPreference))
in C:\xampp\htdocs\SSS\vendor\mongodb\mongodb\src\Database.php line 176
at MongoDB\Database->command(array('ping' => '1'))
in C:\xampp\htdocs\SSS\src\AppBundle\Controller\DefaultController.php line 64
at AppBundle\Controller\DefaultController->indexAction(object(Request))
in C:\xampp\htdocs\SSS\app\bootstrap.php.cache line 3275
at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1')
in C:\xampp\htdocs\SSS\app\bootstrap.php.cache line 3234
at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true)
in C:\xampp\htdocs\SSS\app\bootstrap.php.cache line 3388
at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request), '1', true)
in C:\xampp\htdocs\SSS\app\bootstrap.php.cache line 2594
at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
in C:\xampp\htdocs\SSS\web\app.php line 15
I get the same error when i try to execute this $manager = new \MongoDB\Driver\Manager("mongodb://localhost:27017/"); $rp = new \MongoDB\Driver\ReadPreference(\MongoDB\Driver\ReadPreference::RP_PRIMARY); $server = $manager->selectServer($rp); var_dump($server->getHost());
thank you very much for your reply and for your time , in attempt to execute this : $database = (new \MongoDB\Client)->test;
$cursor = $database->command(['ping' => 1]);
var_dump($cursor->toArray()[0]);
i get this error
MongoDB\Driver\Exception\ConnectionTimeoutException: No suitable servers found (serverSelectionTryOnce set): [connection timeout calling ismaster on '127.0.0.1:27017'] at n/a in C:\xampp\htdocs\SSS\vendor\mongodb\mongodb\src\Database.php line 176
at MongoDB\Driver\Manager->selectServer(object(ReadPreference)) in C:\xampp\htdocs\SSS\vendor\mongodb\mongodb\src\Database.php line 176
at MongoDB\Database->command(array('ping' => '1')) in C:\xampp\htdocs\SSS\src\AppBundle\Controller\DefaultController.php line 64
at AppBundle\Controller\DefaultController->indexAction(object(Request)) in C:\xampp\htdocs\SSS\app\bootstrap.php.cache line 3275
at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1') in C:\xampp\htdocs\SSS\app\bootstrap.php.cache line 3234
at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true) in C:\xampp\htdocs\SSS\app\bootstrap.php.cache line 3388
at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request), '1', true) in C:\xampp\htdocs\SSS\app\bootstrap.php.cache line 2594
at Symfony\Component\HttpKernel\Kernel->handle(object(Request)) in C:\xampp\htdocs\SSS\web\app.php line 15
2019-12-25 18:25 UTC+01:00, Jeremy Mikola notifications@github.com:
I most recently broke down the structure of the server selection error message in this thread, so I'd suggest reading that comment for a more detail explanation. In your case, the root error for failing to select a server is a "connection timeout" attempting to reach the server on
127.0.0.1:27017
. This could either mean that nomongod
process is listening on that host/port or that your PHP environment is not able to make an outgoing connection. Both of those would likely fall outside of the driver itself.I'd suggest attempting to reproduce the error with the most minimal example, such as connecting and executing a
ping
command. We have an example in the library docs that demonstrates how to do so. Two things to note with that example are:
- You'll need to ensure the library classes are available by including Composer's autoloader. We omit that from the doc examples to keep them concise.
- You may want to construct the
MongoDB\Client
object explicitly (see:MongoDB\Client::__construct()
) instead of doing so with no arguments as we have in our examples (again, for conciseness).One other alternative is that you can attempt to connect to the
mongod
host via the HTTP protocol. If you search this repository's issues forfile_get_contents
you should come up with several old comments where I advised users to do this simply to verify that PHP is able to make an outgoing connection. https://github.com/mongodb/mongo-php-library/issues/372#issuecomment-306801722 is one such example.-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/mongodb/mongo-php-library/issues/702#issuecomment-568917694
-- Cordialement, -- Nadia HAREB Ingénieur chercheur Ecole Nationale des Sciences de l'Informatique Laboratoire CRISTAL - Pôle RAMSIS
when i try this file_get_contents('http://127.0.0.1:27017') ; Iget this error
Warning: file_get_contents(http://127.0.0.1:27017): failed to open stream: Aucune connexion n�a pu �tre �tablie car l�ordinateur cible l�a express�ment refus�e. 500 Internal Server Error - ContextErrorException
Please helpp
Given that the file_get_contents()
approach was also unsuccessful, I think one of two things is happening:
mongod
server either not running or not listening on the host/port that you expectBoth of these are beyond the driver/library, so you'll likely need to take your question to a separate forum.
To confirm that the mongod
process is running properly, you can attempt connecting to it with the mongo
shell. If that is unsuccessful, you can review the MongoDB Windows installation docs and/or take this issue to one of the MongoDB community forums. Otherwise, if this is likely a PHP environment issue, I think you should inquire in some PHP community resource, such as Stack Overflow or the XAMPP forums (if you are indeed using XAMPP as your pasted errors suggest).
thank you very much for your reply , actually im running it in windowws 10, but when i deplay the application on OVH (i use exactly the same environnement php 7.1 and mongodb 1.2.8) i get exactly the same error, please how can i confirm that the mongod process is running on my local envirement windows 10
please how can i confirm that the mongod process is running on my local envirement windows 10
In my last comment, I suggested you use the mongo
shell, which ships with the MongoDB server, to verify that you can connect to the server. I also linked the Windows installation docs so you can confirm that the server is properly installed.
This issue does not appear to be directly related to the PHP driver or library, so I am going to close it and request that you consult one of the support channels I referenced in my previous reply for more general support with MongoDB or your PHP environment.
SELinux (CentOS7/8) can cause this error, applying the following rule may resolve it:
setsebool -P httpd_can_network_connect_db 1
Im using alcaeus adapter in my application already built in ext-mongo .
mongodb/mongodb (1.2): PHP Version 7.1.33
Stack Trace (Plain Text) - [1] MongoConnectionException: No suitable servers found (
serverSelectionTryOnce
set): [connection timeout calling ismaster on '127.0.0.1:27017'] at n/a in C:\xampp\htdocs\SSS\vendor\alcaeus\mongo-php-adapter\lib\Alcaeus\MongoDbAdapter\ExceptionConverter.php line 85[2] MongoDB\Driver\Exception\ConnectionTimeoutException: No suitable servers found (
serverSelectionTryOnce
set): [connection timeout calling ismaster on '127.0.0.1:27017'] at n/a in C:\xampp\htdocs\SSS\vendor\mongodb\mongodb\src\Collection.php line 726