Skip to content

Commit d32f008

Browse files
committed
PHPC-2: Persist connection by the dsn
1 parent 95774b1 commit d32f008

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

php_phongo.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,7 @@ mongoc_stream_t* phongo_stream_initiator(const mongoc_uri_t *uri, const mongoc_h
814814
const bson_t *options;
815815
bson_iter_t iter;
816816
struct timeval *timeoutp = NULL;
817+
char *uniqid;
817818
char *errmsg = NULL;
818819
int errcode;
819820
char *dsn;
@@ -851,12 +852,23 @@ mongoc_stream_t* phongo_stream_initiator(const mongoc_uri_t *uri, const mongoc_h
851852
timeout.tv_sec = connecttimeoutms / 1000;
852853
timeout.tv_usec = (connecttimeoutms % 1000) * 1000;
853854

854-
mongoc_log(MONGOC_LOG_LEVEL_DEBUG, MONGOC_LOG_DOMAIN, "Connecting to '%s' (%ld.%06ldms timeout)", dsn, timeout.tv_sec, timeout.tv_usec);
855855
timeoutp = &timeout;
856856
}
857857

858-
stream = php_stream_xport_create(dsn, dsn_len, 0, STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT, (char *)"persistent id", timeoutp, (php_stream_context *)user_data, &errmsg, &errcode);
858+
spprintf(&uniqid, 0, "mongodb://%s:%s@%s:%d/%s?authMechanism=%s&authMechanism=%s",
859+
mongoc_uri_get_username(uri),
860+
mongoc_uri_get_password(uri),
861+
host->host,
862+
host->port,
863+
mongoc_uri_get_database(uri),
864+
mongoc_uri_get_auth_mechanism(uri),
865+
mongoc_uri_get_auth_source(uri)
866+
);
859867

868+
mongoc_log(MONGOC_LOG_LEVEL_DEBUG, MONGOC_LOG_DOMAIN, "Connecting to '%s'", uniqid);
869+
stream = php_stream_xport_create(dsn, dsn_len, 0, STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT, uniqid, timeoutp, (php_stream_context *)user_data, &errmsg, &errcode);
870+
871+
efree(uniqid);
860872
if (!stream) {
861873
bson_set_error (error, MONGOC_ERROR_STREAM, MONGOC_ERROR_STREAM_CONNECT, "Failed connecting to '%s:%d': %s", host->host, host->port, errmsg);
862874
efree(dsn);

0 commit comments

Comments
 (0)