在php版本升级(5.3-> 5.4)之后,当我通过cli运行php脚本时,在最后一次调用后崩溃
<?php
function func($username){
$pass = "password";
$user = "uid=".$username.",ou=users,ou=foo,dc=root";
$conn=ldap_connect("ldaps://myldapserver.com");
$res="ok";
if($conn){
ldap_set_option($conn,LDAP_OPT_PROTOCOL_VERSION,3);
ldap_set_option($conn, LDAP_OPT_REFERRALS, 1);
ldap_set_option($conn, LDAP_OPT_NETWORK_TIMEOUT, 1);
//ldap_close($conn);return $res;
if(!ldap_bind($conn,$user,$pass)){
$res=ldap_error($conn);
}
ldap_close($conn);return $res;
}else{
return "no connect";
}
}
foreach(array(
"user1",
"user2"
) as $user){
echo func($user)."\n";
}
echo "end\n";
?>
此代码始终打印
好
好
结束
但是如果我先分解ldap_close($ conn);返回$ res;没错
更新
使用Zend_Framework 1.11:
<?php
function func($username){
$pass = "password";
$user = "uid=".$username.",ou=users,ou=foo,dc=root";
$host = "myldapserver.com";
$port = "636";
$ldap=new Zend_Ldap();
$options = array(
'host' => $host,
'port' => $port,
'useSsl' => true,
'username' => $user,
'password' => $pass,
'bindRequiresDn' => false,
'accountCanonicalForm' => ACCTNAME_FORM_DN,
'accountDomainName' => 'root',
'baseDn' => 'dc=root'
);
$ldap->setOptions($options);
$res="ok";
try{
$ldap->bind();
$ldap->disconnect();
}catch(Exception $e){
$res=$e->getMessage();
}
return $res;
}
foreach(array(
"user1",
"user2"
) as $user){
echo func($user)."\n";
}
echo "end\n";
?>
相同的结果仍然存在细分错误
更新2
使用xdebug,这是输出
TRACE START [2019-01-15 15:50:16]
0.0001 226928 -> {main}() /var/www/ntk-vitaever-org/scripts/test.php:0
0.0001 228064 -> func() /var/www/ntk-vitaever-org/scripts/test.php:24
0.0001 228400 -> ldap_connect() /var/www/ntk-vitaever-org/scripts/test.php:5
0.0011 228552 >=> resource(4) of type (ldap link)
0.0011 228696 -> ldap_set_option() /var/www/ntk-vitaever-org/scripts/test.php:8
0.0011 228696 >=> TRUE
0.0011 228696 -> ldap_set_option() /var/www/ntk-vitaever-org/scripts/test.php:9
0.0011 228696 >=> TRUE
0.0011 228696 -> ldap_set_option() /var/www/ntk-vitaever-org/scripts/test.php:10
0.0011 228696 >=> TRUE
0.0011 228600 -> ldap_bind() /var/www/ntk-vitaever-org/scripts/test.php:12
0.0111 228600 >=> TRUE
0.0112 228600 -> ldap_close() /var/www/ntk-vitaever-org/scripts/test.php:15
0.0113 228448 >=> TRUE
0.0113 228184 >=> 'ok'
0.0113 228168 -> func() /var/www/ntk-vitaever-org/scripts/test.php:24
0.0113 228432 -> ldap_connect() /var/www/ntk-vitaever-org/scripts/test.php:5
0.0113 228584 >=> resource(5) of type (ldap link)
0.0113 228728 -> ldap_set_option() /var/www/ntk-vitaever-org/scripts/test.php:8
0.0113 228728 >=> TRUE
0.0113 228728 -> ldap_set_option() /var/www/ntk-vitaever-org/scripts/test.php:9
0.0113 228728 >=> TRUE
0.0113 228728 -> ldap_set_option() /var/www/ntk-vitaever-org/scripts/test.php:10
0.0113 228728 >=> TRUE
0.0114 228632 -> ldap_bind() /var/www/ntk-vitaever-org/scripts/test.php:12
0.0144 228632 >=> TRUE
0.0144 228632 -> ldap_close() /var/www/ntk-vitaever-org/scripts/test.php:15
0.0145 228480 >=> TRUE
0.0145 228216 >=> 'ok'
0.0146 227776 >=> 1
0.0146 8240
TRACE END [2019-01-15 15:50:16]
有用吗?