2016-07-07 69 views
1

我试图用这个PHP代码连接到远程服务器:当通过PHP最大极限尺寸误差连接到MongoDB的出现

if ($mongo = new MongoClient('mongodb://root:password#@111.111.111.11:2222')) 
    if ($db = $mongo->selectDB("test")) 

Fatal error: Uncaught exception 'MongoConnectionException' with message 'Failed to connect to: 111.111.111.11:2222: send_package: data corruption: the returned size of the reply (759714607) is larger than the maximum allowed size (4194304)' in /var/www/html/mongo/index.php:24 Stack trace: #0 /var/www/html/mongo/index.php(24): MongoClient->__construct('mongodb://root:...') #1 {main} thrown in /var/www/html/mongo/index.php on line 24

+1

您是否正在连接到正确的MongoDB端口?我偶然发现连接到memcached聊天协议端口时遇到问题... – jpaljasma

回答

0

我用这个命令来创建SSH隧道:

autossh -C -p 22 -l {name} -N -o ConnectTimeout=5 -o TCPKeepAlive=yes -o NumberOfPasswordPrompts=3 -o ControlMaster=no -o PreferredAuthentications=password -L 27018:localhost:27017 [email protected]

它基本上创建了本地机器和数据库服务器之间的ssh连接隧道。打开端口为27018,结束端口为27017,即MongoDB端口。

,然后在代码我用这个连接参数:

$mongo = new MongoClient('localhost:27018'); 

连接SSH隧道的开放口。