【发布时间】:2013-11-03 22:53:01
【问题描述】:
我的 PHP 脚本中的 find() 查询仍然会忽略尝试 mongodb 全局超时等。 我想要一个 findOne({...}) 或 find({...}) 查找并在超时前等待数据库服务器最多 20 毫秒。
如何确保 PHP 不将此设置用作软限制?它仍然被忽略并在 5 秒后处理答案。
这是 PHP mongo 驱动程序的错误吗?
例子:
MongoCursor::$timeout=20;
$nosql_server=new Mongo('mongodb://user:pw@'.implode(",",$arr_replicas).'',array("replicaSet" => "gmt","timeout"=>10)) OR troubles("too slow to connect");
$nosql_db=$nosql_server->selectDB('aDB');
$nosql_collection_mcol=$nosql_db->mcol;
$testFind=$nosql_collection_mcol->find(array('crit'=>123));
//If PHP considered the MongoCursor::$timeout, I'd expect the prev. line to be skipped or throwing a mongo/timeout exception if DB does not return the find result cursor ready within 20ms.
//However, I arrive with this line after seconds, without exception whenever the DB has some lock or delay, without skipping previous line.
【问题讨论】:
-
您是在 php.ini 配置中还是在代码中设置超时?无论哪种方式,我们可以看看您使用什么代码来进行查找吗?
-
我在脚本中设置了超时。已编辑:您现在可以找到示例代码。