Skip to content

Commit 82d3874

Browse files
committed
Merge pull request #272
2 parents e6af431 + e097a09 commit 82d3874

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

php_phongo.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ mongoc_stream_t* phongo_stream_initiator(const mongoc_uri_t *uri, const mongoc_h
11231123

11241124
options = mongoc_uri_get_options(uri);
11251125

1126-
if (bson_iter_init_find (&iter, options, "connecttimeoutms") && BSON_ITER_HOLDS_INT32 (&iter)) {
1126+
if (bson_iter_init_find_case (&iter, options, "connecttimeoutms") && BSON_ITER_HOLDS_INT32 (&iter)) {
11271127
int32_t connecttimeoutms = MONGOC_DEFAULT_CONNECTTIMEOUTMS;
11281128

11291129
if (!(connecttimeoutms = bson_iter_int32(&iter))) {
@@ -1134,6 +1134,7 @@ mongoc_stream_t* phongo_stream_initiator(const mongoc_uri_t *uri, const mongoc_h
11341134
timeout.tv_usec = (connecttimeoutms % 1000) * 1000;
11351135

11361136
timeoutp = &timeout;
1137+
MONGOC_DEBUG("Applying connectTimeoutMS: %d", connecttimeoutms);
11371138
}
11381139

11391140
spprintf(&uniqid, 0, "%s:%d[%s]", host->host, host->port, mongoc_uri_get_string(uri));

tests/standalone/bug0655.phpt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
--TEST--
2+
PHPC-655: Use case insensitive parsing for Manager connectTimeoutMS array option
3+
--SKIPIF--
4+
<?php if (defined("HHVM_VERSION_ID")) exit("skip HHVM does not use custom streams"); ?>
5+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
6+
--FILE--
7+
<?php
8+
require_once __DIR__ . "/../utils/basic.inc";
9+
10+
$command = new MongoDB\Driver\Command(['ping' => 1]);
11+
12+
// Invalid host cannot be resolved
13+
$manager = new MongoDB\Driver\Manager('mongodb://invalid.host:27017', ['connectTimeoutMS' => 1]);
14+
15+
ini_set('mongodb.debug', 'stderr');
16+
17+
echo throws(function() use ($manager, $command) {
18+
$manager->executeCommand(DATABASE_NAME, $command);
19+
}, 'MongoDB\Driver\Exception\ConnectionTimeoutException'), "\n";
20+
21+
// Valid host refuses connection
22+
$manager = new MongoDB\Driver\Manager('mongodb://localhost:54321', ['CONNECTTIMEOUTMS' => 1]);
23+
24+
echo throws(function() use ($manager, $command) {
25+
$manager->executeCommand(DATABASE_NAME, $command);
26+
}, 'MongoDB\Driver\Exception\ConnectionTimeoutException'), "\n";
27+
28+
ini_set('mongodb.debug', 'off');
29+
30+
?>
31+
===DONE===
32+
<?php exit(0); ?>
33+
--EXPECTF--
34+
%a
35+
[%s] PHONGO: DEBUG > Applying connectTimeoutMS: 1
36+
[%s] PHONGO: DEBUG > Connecting to 'invalid.host:27017[mongodb://invalid.host:27017]'
37+
%a
38+
OK: Got MongoDB\Driver\Exception\ConnectionTimeoutException
39+
No suitable servers found (`serverselectiontryonce` set): %s
40+
%a
41+
[%s] PHONGO: DEBUG > Applying connectTimeoutMS: 1
42+
[%s] PHONGO: DEBUG > Connecting to 'localhost:54321[mongodb://localhost:54321]'
43+
%a
44+
OK: Got MongoDB\Driver\Exception\ConnectionTimeoutException
45+
No suitable servers found (`serverselectiontryonce` set): %s
46+
===DONE===

0 commit comments

Comments
 (0)