level 3
php 连接mongodb 闲置30秒后关闭,重新连接连接不上,调用5次后又能连接,求指教怎样能解决
Failed to connect to: mongo.duapp.com:8908: send_package: error reading from socket: The socket is closed
2014年10月11日 02点10分
1
level 1
$mongoClient=NULL;
$mongoDB=NULL;
try{
$mongoClient = new MongoClient("mongodb://{$host}:{$port}");
$mongoDB = $mongoClient->selectDB($dbname);
$mongoDB->authenticate($user, $pwd);
}catch(Exception $ex){
$mongoClient = new MongoClient("mongodb://{$host}:{$port}");
$mongoDB = $mongoClient->selectDB($dbname);
$mongoDB->authenticate($user, $pwd);
}
/*这里写你的业务逻辑代码*/
$mongoClient->close(); /*一定要记得close*/
我是昨天要用bae的这个东西碰到的,研究了一晚上搞出来的,给分吧。
2015年01月20日 02点01分
3
catch 里面能够重新连接上吗?
2015年08月14日 05点08分