Handle PHP errors, dump variables, execute PHP code remotely in Google Chrome
Handle PHP errors, dump variables, execute PHP code remotely in Google Chrome
PHP Console allows you to handle PHP errors & exceptions, dump variables, execute PHP code remotely and many other things using Google Chrome extension PHP Console and PhpConsole server library.
*For projects with PHP setSourcesBasePath('/path/to/project');
So paths like /path/to/project/module/file.php will be displayed on client as /module/file.php.
If your internal server encoding is not UTF-8, so you need to call:
$connector->setServerEncoding('CP1251');PhpConsole server library is optimized for lazy initialization only for clients that have Google Chrome extension PHP Console installed. There is example of correct initialization PhpConsole on your production server.
$connector->setPassword('yohoho123', true);
Clients will need to enter a password to get access to PHP Console server data. All passwords are stored on client as SHA-256 hashes. Second argument says that the PHP Console authorization token will depend on the client IP.
$connector->enableSslOnlyMode();So all PHP Console clients will be automatically redirected to HTTPS.
$connector->setAllowedIpMasks(array('192.168.*.*', '2001:0:5ef5:79fb:*:*:*:*'));There is a PhpConsole\Handler class that initializes PHP errors & exceptions handlers and provides the next features:
$handler->handleException($exception).$handler->debug($var, 'some.tags').Initialize PhpConsole\Handler in the top of your main project script:
$handler = PhpConsole\Handler::getInstance();
/* You can override default Handler behavior:
$handler->setHandleErrors(false); // disable errors handling
$handler->setHandleExceptions(false); // disable exceptions handling
$handler->setCallOldHandlers(false); // disable passing errors & exceptions to prviously defined handlers
*/
$handler->start(); // initialize handlersPHP Console has multifunctional and smart vars dumper that allows to
$connector->getDumper()).$connector->getDebugDispatcher()->detectTraceAndSource = true).Longest native debug method call:
PhpConsole\Connector::getInstance()->getDebugDispatcher()->dispatchDebug($var, 'some.tags');Shorter call debug from Handler:
PhpConsole\Handler::getInstance()->debug($var, 'some.tags');Shortest call debug using global PC class
PhpConsole\Helper::register(); // it will register global PC class
// ...
PC::debug($var, 'tag');
PC::tag($var);Custom call debug by user defined function
function d($var, $tags = null) {
PhpConsole\Connector::getInstance()->getDebugDispatcher()->dispatchDebug($var, $tags, 1);
}
d($var, 'some.tags');PHP Console provide a way to execute PHP code on your server remotely, from Google Chrome extension terminal.
output, return and time data$connector = PhpConsole\Connector::getInstance();
$connector->setPassword($password);
// Configure eval provider
$evalProvider = $connector->getEvalDispatcher()->getEvalProvider();
$evalProvider->addSharedVar('post', $_POST); // so "return $post" code will return $_POST
$evalProvider->setOpenBaseDirs(array(__DIR__)); // see http://php.net/open-basedir
$connector->startEvalRequestsListener(); // must be called in the end of all configurationsThere is PHP Console implementation of PSR-3 interface. to integrate PHP Console with PSR-3 compitable loggers(e.g. Monolog). See PhpConsole\PsrLogger.
Read this article if you want to configure PHP Console extension to open errors/exceptions source file:line right in your IDE, just by click on the button in Notification popup.
v1.x to v3.xIf you have used PhpConsole v1.x and want to migrate to v3.x without any code changes, so just use PhpConsole\OldVersionAdapter:
PhpConsole\OldVersionAdapter::register(); // register PhpConsole v1.x class emulator
// Call old PhpConsole v1 methods as is
PhpConsole::start(true, true, $_SERVER['DOCUMENT_ROOT']);
PhpConsole::debug('Debug using old method PhpConsole::debug()', 'some,tags');
debug('Debug using old function debug()', 'some,tags');
echo $undefinedVar;
PhpConsole::getInstance()->handleException(new Exception('test'));
// Call new PhpConsole methods, if you want :)
PhpConsole\Connector::getInstance()->setServerEncoding('cp1251');
PhpConsole\Helper::register();
PC::debug('Debug using new methods');But, anyway, if you can't migrate to new version of PHP Console because of using PHP < 5.3 on your servers, then you can use old deprecated version of PHP Console.
No open issues yet, or sync has not completed.