ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

PHP脚本中的PHP LDAP调试输出

2019-10-12 15:33:35  阅读:226  来源: 互联网

标签:php ldap debugging


我想在PHP脚本(Windows环境)中获取ldap连接的调试信息.要激活调试输出,您必须使用ldap_set_option调用ldap_connect:

ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);

并且有必要从命令行运行.否则,您将无法获得调试输出.在要求中,此调试输出未显示.

<?php

// Set the ldap server
$ldapurl = "foo.bar";

// Set debugging
ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);

// connect to ldap server
$ldapconn = ldap_connect($ldapurl) or die ("Couldn't connect"); 

// binding to ldap server
$ldapbind = ldap_bind($ldapconn, $ldapuser, $ldappass);

?>

命令行的结果:

C:\>C:\Apache\php\php-cgi.exe -f C:\Apache\htdocs\ldap_debug.php
    ldap_url_parse_ext(ldap://localhost/)
    ldap_init: trying c:\openldap\sysconf\ldap.conf
    ldap_init: HOME env is NULL
    ldap_init: trying ldaprc
    ldap_init: LDAPCONF env is NULL
    ldap_init: LDAPRC env is NULL
    ldap_create
    ldap_bind_s
    ldap_simple_bind_s
    ldap_sasl_bind_s
    ldap_sasl_bind
    ldap_send_initial_request
    ldap_new_connection 1 1 0
    ldap_int_open_connection
    ldap_connect_to_host: TCP foo.bar:389
    ldap_new_socket: 776
    ldap_prepare_socket: 776
    ldap_connect_to_host: Trying 192.168.42.20:389
    ldap_pvt_connect: fd: 776 tm: -1 async: 0
    ldap_open_defconn: successful
    ldap_send_server_request
    ldap_result ld 091BAC10 msgid 1
    wait4msg ld 091BAC10 msgid 1 (infinite timeout)
    wait4msg continue ld 091BAC10 msgid 1 all 1
    ** ld 091BAC10 Connections:
    * host: foo.bar  port: 389  (default)
      refcnt: 2  status: Connected
      last used: Mon Dec 15 09:16:49 2014


    ** ld 091BAC10 Outstanding Requests:
     * msgid 1,  origid 1, status InProgress
       outstanding referrals 0, parent count 0
      ld 091BAC10 request count 1 (abandoned 0)
    ** ld 091BAC10 Response Queue:
       Empty
      ld 091BAC10 response count 0
    ldap_chkResponseList ld 091BAC10 msgid 1 all 1
    ldap_chkResponseList returns ld 091BAC10 NULL
    ldap_int_select
    read1msg: ld 091BAC10 msgid 1 all 1
    read1msg: ld 091BAC10 msgid 1 message type bind
    read1msg: ld 091BAC10 0 new referrals
    read1msg:  mark request completed, ld 091BAC10 msgid 1
    request done: ld 091BAC10 msgid 1
    res_errno: 0, res_error: <>, res_matched: <>
    ldap_free_request (origid 1, msgid 1)
    ldap_parse_result
    ldap_msgfree
    ldap_free_connection 1 1
    ldap_send_unbind
    ldap_free_connection: actually freed

现在,我想在请求中执行此操作(http://localhost/ldap_debug.php?cmd):

<?php

if (isset($_REQUEST['cmd']))
{
    $aOutput = array();
    $sCmdLine = "C:\\Apache\\php\\php-cgi.exe -f ".__FILE__;
    exec($sCmdLine, $aOutput);
    print_r($aOutput);
    exit;
}

// Set the ldap server
$ldapurl = "foo.bar";

// Set debugging
ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);

// connect to ldap server
$ldapconn = ldap_connect($ldapurl) or die ("Couldn't connect"); 

// binding to ldap server
$ldapbind = ldap_bind($ldapconn, $ldapuser, $ldappass);

?>

但是结果数组是$aOutput为空.有什么提示吗?

解决方法:

感谢Redirect Windows cmd stdout and stderr to a single file,我可以回答我自己的问题.诀窍是将stderr重定向到stdout:

$sCmdLine = "C:\\Apache\\php\\php-cgi.exe -f ".__FILE__." 2>&1";

标签:php,ldap,debugging
来源: https://codeday.me/bug/20191012/1901126.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有