douyi9787 2017-03-20 08:30
浏览 48

使用mongo php ext连接到mongo数据库时超时

Timeout while connecting to MongoDB database with mongo php ext under Ubuntu 12.04 and php 5.6

I'm using

  • latest Apache 2.4
  • Ubuntu 12.04
  • php 5.6 with mongo ext Version 1.6.14
  • MongoDB v3.4 running in an lxc container

And the problem is when I connect to the mongo database.

I'm using this connection string:

mongodb://myDbUser:passW0rT@0.0.0.0:27020/myDb

(password, database and addr have been changed).

I have verified that php mongo ext is installed, with this code:

echo extension_loaded("mongo") ? "loaded
" : "not loaded
"; //prints loaded.
if (class_exists('\MongoClient')) {
   echo 'is Mongo Client'."
";//this is printed
}
else {
   echo 'no Mongo Client'."
";
}


try {
    $client = new MongoClient('mongodb://myDbUser:passW0rT@0.0.0.0:27020/myDb', []);
} catch (Exception $ex) {
    echo $ex->getMessage();//prints Failed to connect to: 0.0.0.0:27020: Connection timed out 
}

What is more strange I can connect to this database using MongoClient and in addition to this I can connect to this database by my local server running on my computer (Win 10).

The problem appears also when I use security.authorization set to enabled and without difference set to disabled – then I use dsn mongodb://0.0.0.0:27020 Unfortunately server's response always gives timeout error when I enter web addr using www (domain which is on the server where mongo database is installed).

It could be one clue that server where mongo is installed is server which runs as container which means that I have to add port number to connect eg. via ssh.

I even changed the server from ngix to apache and problem didn't disappear.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求解 yolo算法问题
    • ¥15 虚拟机打包apk出现错误
    • ¥30 最小化遗憾贪心算法上界
    • ¥15 用visual studi code完成html页面
    • ¥15 聚类分析或者python进行数据分析
    • ¥15 三菱伺服电机按启动按钮有使能但不动作
    • ¥15 js,页面2返回页面1时定位进入的设备
    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝