What best practices should be followed when configuring SSL for LDAP connections in PHP?

When configuring SSL for LDAP connections in PHP, it is important to ensure that the LDAP server is using a valid SSL certificate and that the PHP LDAP extension is compiled with SSL support. Additionally, the LDAP server's certificate should be trusted by the client machine, and the connection should be made over LDAPS (LDAP over SSL) protocol.

$ldapServer = 'ldaps://ldap.example.com';
$ldapPort = 636;

$ldapConn = ldap_connect($ldapServer, $ldapPort);

ldap_set_option($ldapConn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldapConn, LDAP_OPT_REFERRALS, 0);

ldap_start_tls($ldapConn);

// Perform LDAP operations here

ldap_close($ldapConn);