@@ -1004,7 +1004,9 @@ static mongoc_uri_t *php_phongo_make_uri(const char *uri_string, bson_t *options
10041004 !strcasecmp (key , "safe" ) ||
10051005 !strcasecmp (key , "slaveok" ) ||
10061006 !strcasecmp (key , "w" ) ||
1007- !strcasecmp (key , "wtimeoutms" )) {
1007+ !strcasecmp (key , "wtimeoutms" ) ||
1008+ !strcasecmp (key , "maxstalenessms" )
1009+ ) {
10081010 continue ;
10091011 }
10101012
@@ -1090,7 +1092,9 @@ static bool php_phongo_apply_rp_options_to_uri(mongoc_uri_t *uri, bson_t *option
10901092
10911093 if (!bson_iter_init_find_case (& iter , options , "slaveok" ) &&
10921094 !bson_iter_init_find_case (& iter , options , "readpreference" ) &&
1093- !bson_iter_init_find_case (& iter , options , "readpreferencetags" )) {
1095+ !bson_iter_init_find_case (& iter , options , "readpreferencetags" ) &&
1096+ !bson_iter_init_find_case (& iter , options , "maxstalenessms" )
1097+ ) {
10941098 return true;
10951099 }
10961100
@@ -1141,6 +1145,19 @@ static bool php_phongo_apply_rp_options_to_uri(mongoc_uri_t *uri, bson_t *option
11411145 return false;
11421146 }
11431147
1148+ /* Handle maxStalenessMS, and make sure it is not combined with primary
1149+ * readPreference */
1150+ if (bson_iter_init_find_case (& iter , options , "maxstalenessms" ) && BSON_ITER_HOLDS_INT32 (& iter )) {
1151+ if (mongoc_read_prefs_get_mode (new_rp ) == MONGOC_READ_PRIMARY ) {
1152+ phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Primary read preference mode conflicts with maxStalenessMS" );
1153+ mongoc_read_prefs_destroy (new_rp );
1154+
1155+ return false;
1156+ }
1157+
1158+ mongoc_read_prefs_set_max_staleness_ms (new_rp , bson_iter_int32 (& iter ));
1159+ }
1160+
11441161 /* This may be redundant in light of the last check (primary with tags), but
11451162 * we'll check anyway in case additional validation is implemented. */
11461163 if (!mongoc_read_prefs_is_valid (new_rp )) {
0 commit comments