donglu4159 2014-12-15 08:55
浏览 74
已采纳

PHP脚本中的PHP LDAP调试输出

I want to fetch debug information of an ldap connection in a PHP script (Windows Environment). To activate the debug output you have to use ldap_set_option calling ldap_connect:

ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);

And it is necessary to run the from command line. Otherwise you wont get the debug output. In a reqeust this debug output is not shown.

<?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);

?>

The result of the command-line:

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

Now I want to do this in a request (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);

?>

But the result array is $aOutput is empty. Any hints?

  • 写回答

1条回答 默认 最新

  • douchui4815 2014-12-15 10:05
    关注

    Thanks to Redirect Windows cmd stdout and stderr to a single file I can answer my own question. The trick is to redirect stderr to stdout:

    $sCmdLine = "C:\\Apache\\php\\php-cgi.exe -f ".__FILE__." 2>&1";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示