PHP Console tool usage and sharing

PHP Console:https://github.com/barbushin/php-console#php-console-server-library

Features

The PHP Console tool and FirePHP have similar functions, providing the following functions:

Handle PHP errors, dump variables, execute PHP code remotely in Google Chrome

Demo

First install the PHP Console plugin in Chrome:

https://chrome.google.com/webstore/detail/php-console/nfhmhhlpfleoednkpnnnkolmclajemef

Secondly, introduce the PHP Console library into the PHP code, and then call to output the corresponding debugging information:

The following example index2.php:

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

Output debugging information to the console, as shown below:

Principle introduction

The PHP Console tool outputs the debugging information to the HTTP response header PHP-Console, and then the PHP Console plug-in analyzes the response header PHP-Console string to output corresponding debugging information.

 

appendix

The PHP Console provides the function of protecting debugging information with a password. The following example sets a password on the server side:

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

At this time, you can see that only when the client enters the correct password:

Only then will the response header output the corresponding debugging information:

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

Guess you like

Origin blog.csdn.net/nana837/article/details/113040588