我试图使用以下PHP代码连接到远程服务器:
if ($mongo = new MongoClient('mongodb://root:password#@111.111.111.11:2222'))
if ($db = $mongo->selectDB("test"))
致命错误:无法连接到: 111.111.111.11:2222:数据损坏:应答(759714607)的返回大小大于/var/www/html/mongo/index.php中允许的最大大小(4194304):24堆栈跟踪:#0 /var/var/html/mongo/index.php(24):MongoClient->__construct('mongodb://root:...') #1 {main 1)抛入第24行中的/var/www/html/mongo/index.php
发布于 2016-07-29 00:53:46
我使用这个命令创建ssh隧道:
autossh -C -p 22 -l
{name}
-N -o ConnectTimeout=5 -o TCPKeepAlive=yes -o NumberOfPasswordPrompts=3 ControlMaster=no -o PreferredAuthentications=password -L 27018:localhost:27017 root@420.213.412.21
它基本上用数据库在本地机器和服务器之间创建了ssh连接隧道。开放端口为27018,结束端口为27017,即MongoDB端口。
然后,对于代码中的连接参数,我使用了以下方法:
$mongo = new MongoClient('localhost:27018');
连接到ssh隧道的开口端口。
https://stackoverflow.com/questions/38242205
复制相似问题