Skip to content
This repository was archived by the owner on Feb 1, 2022. It is now read-only.

Commit 34e6d2c

Browse files
committed
Merge pull request #746
2 parents 0ef35fb + 880e942 commit 34e6d2c

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

cursor.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ PHP_METHOD(MongoCursor, reset)
10281028
PHP_METHOD(MongoCursor, count)
10291029
{
10301030
zend_bool all = 0;
1031-
zval *response, *cmd, **n;
1031+
zval *response, *cmd, *options, **n;
10321032
mongo_cursor *cursor;
10331033
mongoclient *link;
10341034
char *cname, *dbname;
@@ -1063,8 +1063,13 @@ PHP_METHOD(MongoCursor, count)
10631063
add_assoc_long(cmd, "skip", cursor->skip);
10641064
}
10651065

1066-
response = php_mongo_runcommand(cursor->zmongoclient, &cursor->read_pref, dbname, strlen(dbname), cmd, NULL, 0, NULL TSRMLS_CC);
1066+
MAKE_STD_ZVAL(options);
1067+
array_init(options);
1068+
add_assoc_long(options, "socketTimeoutMS", cursor->timeout);
1069+
1070+
response = php_mongo_runcommand(cursor->zmongoclient, &cursor->read_pref, dbname, strlen(dbname), cmd, options, 0, NULL TSRMLS_CC);
10671071
zval_ptr_dtor(&cmd);
1072+
zval_ptr_dtor(&options);
10681073
efree(dbname);
10691074

10701075
if (!response) {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--TEST--
2+
MongoCursor::count() inherits socket timeout from cursor
3+
--SKIPIF--
4+
<?php if (version_compare(phpversion(), "5.3.0", "lt")) exit("skip setCallback and closures are 5.3+"); ?>
5+
<?php if (!MONGO_STREAMS) { echo "skip This test requires streams support"; } ?>
6+
<?php require_once "tests/utils/standalone.inc"; ?>
7+
--FILE--
8+
<?php require_once "tests/utils/server.inc"; ?>
9+
<?php
10+
11+
$host = MongoShellServer::getStandaloneInfo();
12+
$m = new MongoClient($host);
13+
$c = $m->selectCollection(dbname(), collname(__FILE__));
14+
15+
$c->drop();
16+
$c->insert(array('x' => 1));
17+
$c->insert(array('x' => 2));
18+
$c->insert(array('x' => 3));
19+
$c->insert(array('x' => 4));
20+
21+
printLogs(MongoLog::ALL, MongoLog::ALL, "/timeout/i");
22+
23+
printf("Count all documents, default timeout: %d\n", $c->find()->count());
24+
echo "\n";
25+
printf("Count all documents, timeout = 1000: %d\n", $c->find()->timeout(1000)->count());
26+
?>
27+
===DONE===
28+
--EXPECTF--
29+
Initializing cursor timeout to 30000 (from connection options)
30+
Initializing cursor timeout to 30000 (from connection options)
31+
No timeout changes for %s:%d;-;%s;%d
32+
No timeout changes for %s:%d;-;%s;%d
33+
Count all documents, default timeout: 4
34+
35+
Initializing cursor timeout to 30000 (from connection options)
36+
Initializing cursor timeout to 30000 (from connection options)
37+
Setting the stream timeout to 1.000000
38+
Now setting stream timeout back to 30.000000
39+
Setting the stream timeout to 1.000000
40+
Now setting stream timeout back to 30.000000
41+
Count all documents, timeout = 1000: 4
42+
===DONE===

0 commit comments

Comments
 (0)