php activerecord身份验证无法连接ldap服务器

I need to authenticate user in active directory in php (using yii framewrok). On one of computer in the network I have virtual machine with windows 2008 server with active directory (port 5000 is used) and I try to connect it using ldap and authenticate user. Controller name is (server1.domain_name).

My code is like this one:

$hostName = '192.168.139.94'; 
$port = 5000;

$userName = 'User1@domain_name';
$password = 'password';

$ldap = ldap_connect($hostName, $port);
if ($bind = ldap_bind($ldap, $userName, $password)) {
    echo 'success';
    // log them in!
} else {
    // error message
    echo 'failed';
}

But get warning:

ldap_bind() [<a href='function.ldap-bind'>function.ldap-bind</a>]: Unable to bind to server: Can't contact LDAP server

Could you please tell what's the problem? How to get more information what causes problem?

Very strange port 5000 for Active-Directory. Native Active-Directory waits on 389, and Lightweigh Directory Server (LDS) naturaly waits on port 50000, when AD exists on the machine. Are you sure for the port ?

Once the port verified, you can add these two lines between ldap_connect and ldap_bind

ldap_connec(...)
ldap_set_option ($ldap, LDAP_OPT_REFERRALS, 0);
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_bind(...)

The problem was that 389 port was use not 5000.

It's a silly error, 389 port was used, not 5000. I was simply misinformed. Thank you for all answers.