PHP Console提供了通过密码来保护调试信息的功能,如下例,在服务器端设置密码:
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');
此时可以看到只有当客户端输入正确的密码:
此时响应头部才会输出相应的调试信息:
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