diff --git a/lib/Net/LDAP3.php b/lib/Net/LDAP3.php
index 7461be98fd0e2616862a6ceb28da48f2a58a7843..a4e3bca4dae2fc546601d1cdf109991411ce4bac 100644
--- a/lib/Net/LDAP3.php
+++ b/lib/Net/LDAP3.php
@@ -2234,7 +2234,8 @@ class Net_LDAP3
         $tls  = $this->config_get('use_tls', false);
 
         foreach ((array) $this->config_get('hosts') as $host) {
-            $this->_debug("C: Connect [$host:$port]");
+            $ldap_uri = $this->_host2uri($host, $port);
+            $this->_debug("C: Connect [{$ldap_uri}]");
 
             $_ldap_cfg = [
                 'host'   => $host,
@@ -2247,8 +2248,11 @@ class Net_LDAP3
 
             $_ldap_schema_cache_cfg = [
                 'max_age' => 86400,
-                'path' => sprintf('%s/%s-Net_LDAP2_Schema.cache',
-                    sys_get_temp_dir() ?: '/tmp', str_replace('://', ':', $host) . (strpos($host, ":$port") ? '' : ":$port")),
+                'path' => sprintf(
+                    '%s/%s-Net_LDAP2_Schema.cache',
+                    sys_get_temp_dir() ?: '/tmp',
+                    str_replace(['://', '/'], ':', $ldap_uri)
+                ),
             ];
 
             $_ldap = Net_LDAP2::connect($_ldap_cfg);