嘗試mongodb全局超時等仍被我的PHP腳本中的find()查詢忽略。 我想要一個findOne({...})或find({...})查找,並在超時之前等待數據庫服務器的最長20ms。PHP/MongoDB:find()忽略超時設置
如何確保PHP不會將此設置用作軟限制?它仍然被忽略,甚至在5秒後處理答案。
這是一個PHP mongo驅動程序錯誤?
實施例:
MongoCursor::$timeout=20;
$nosql_server=new Mongo('mongodb://user:[email protected]'.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配置或代碼中設置超時?無論哪種方式,我們可以看到您使用的代碼來執行查找嗎? – halfer
我在腳本中設置了超時。編輯:您現在可以找到示例代碼。 – ledy