我正在尝试在我的本地电脑上运行我的应用程序。云上的一切看起来都很好,它可以工作并使用以下代码连接到 MongoDB:
$services_json = json_decode(getenv("VCAP_SERVICES"),true);
$mongo_config = $services_json["mongodb-1.8"][0]["credentials"];
// Generally will be localhost if you're querying from the machine that Mongo is installed on
$config['mongo_host'] = $mongo_config["hostname"];
// Generally will be 27017 unless you've configured Mongo otherwise
$config['mongo_port'] = $mongo_config["port"];
// The database you want to work from (required)
$config['mongo_db'] = $mongo_config["db"];
// Leave blank if Mongo is not running in auth mode
$config['mongo_user'] = $mongo_config["username"];
$config['mongo_pass'] = $mongo_config["password"];
但是由于我无法从本地 pc 获取 vcap_services,因此我使用常量值进行连接,以将我的应用程序连接到 appfog 上的远程 mongo 服务器:
// Generally will be localhost if you're querying from the machine that Mongo is installed on
$config['mongo_host'] = "***";
// Generally will be 27017 unless you've configured Mongo otherwise
$config['mongo_port'] = "***";
// The database you want to work from (required)
$config['mongo_db'] = "db";
// Leave blank if Mongo is not running in auth mode
$config['mongo_user'] = "***";
$config['mongo_pass'] = "***";
但是当我尝试通过 执行应用程序时http://localhost/my-app
,它给了我这个错误:
Unable to connect to MongoDB: Failed to connect to: ***: Connection timed out
可能是什么问题?
*出于隐私考虑,已删除值。