PHP Console工具使用分享

PHP Console工具使用分享

http://www.open-open.com/lib/view/open1416193590414.html

您的评价:
     
不错
 收藏该经验    
 

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:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
  
require_once (__DIR__ .  '/../src/PhpConsole/__autoload.php' );
  
// 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' );

输出调试信息到控制台,如下图:

20141028202013805.png

原理介绍

PHP Console工具通过将调试信息输出到http响应头PHP-Console,然后PHP Console插件分析响应头PHP-Console字符串输出相应调试信息。

20141028202101906.png

 

附录

PHP Console提供了通过密码来保护调试信息的功能,如下例,在服务器端设置密码:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
  
require_once (__DIR__ .  '/../src/PhpConsole/__autoload.php' );
  
$password 'test' ;
$connector = PhpConsole\Connector::getInstance();
$connector ->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' );

此时可以看到只有当客户端输入正确的密码:

20141028204037953.png

此时响应头部才会输出相应的调试信息:

?
1
2
3
4
5
6
7
8
9
HTTP /1 .1 200 OK
Server: Tengine /2 .0.3
Date: Tue, 28 Oct 2014 12:36:04 GMT
Content-Type: text /html
Connection: keep-alive
X-Powered-By: PHP /5 .3.29
PHP-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
来自:http://blog.csdn.net/billfeller/article/details/40554625
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值