您好,欢迎访问一九零五行业门户网

PHP Console工具使用分享

作者:zhanhailiang 日期:2014-10-28
php console:https://github.com/barbushin/php-console#php-console-server-library
功能介绍 php console工具和firephp功能相似,提供以下功能:
handle php errors, dump variables, execute php code remotely in google chrome
demo 首先在chrome中安装php console插件:
https://chrome.google.com/webstore/detail/php-console/nfhmhhlpfleoednkpnnnkolmclajemef
其次在php代码中引入php console库,然后调用输出相应调试信息:
如下例index2.php:
start();$handler->debug('called from handler debug', 'some.three.tags'); $array = array( 'test' => 1, 'test2' => 1, 'key' => array( 1, 2, 3, 4, ), );$handler->debug($array, 'test.wiki.wade.zhan');
输出调试信息到控制台,如下图:
原理介绍 php console工具通过将调试信息输出到http响应头php-console,然后php console插件分析响应头php-console字符串输出相应调试信息。
附录 php console提供了通过密码来保护调试信息的功能,如下例,在服务器端设置密码:
setpassword($password); // call debug from phpconsole\handler$handler = phpconsole\handler::getinstance();$handler->start();$handler->debug('called from handler debug', 'some.three.tags'); $array = array( 'test' => 1, 'test2' => 1, 'key' => array( 1, 2, 3, 4, ), );$handler->debug($array, 'test.wiki.wade.zhan');
此时可以看到只有当客户端输入正确的密码:
此时响应头部才会输出相应的调试信息:
http/1.1 200 okserver: tengine/2.0.3date: tue, 28 oct 2014 12:36:04 gmtcontent-type: text/htmlconnection: keep-alivex-powered-by: php/5.3.29php-console-postpone: {protocol:5,ispostponed:true,id:6957661441226218549514727634}php-console: {protocol:5,auth:{publickey:bf802ef9f6d61a5d4a720892a79bf8285d92c31c2a99be2931b504dc54eeb209,issuccess:true},docroot:\/usr\/local\/wwwroot\/dokuwiki,sourcesbasepath:null,getbackdata:null,islocal:false,issslonlymode:false,isevalenabled:false,messages:[{type:debug,tags:[some,three,tags],data:called from handler debug,file:null,line:null,trace:null},{type:debug,tags:[test,wiki,wade,zhan],data:{test:1,test2:1,key:[1,2,3,4]},file:null,line:null,trace:null}]}content-length: 0
其它类似信息

推荐信息