简体   繁体   English

如何使用firefox开发人员工具从PHP记录服务器端消息

[英]How to use firefox developer tools to log server side messages from PHP

I am trying to switch firefox developer tools for server side debugging because firebug is no longer working with firePHP. 我试图切换firefox开发人员工具进行服务器端调试,因为firebug不再使用firePHP。

Checked the documentation I found this information: 查看了我发现此信息的文档:

Firebug extensions like FirePHP allow to log server-side messages to the Firebug console. 像FirePHP这样的Firebug扩展允许将服务器端消息记录到Firebug控制台。 This functionality is already integrated into the DevTools using the ChromeLogger protocol and doesn't require any extensions to be installed. 此功能已使用ChromeLogger协议集成到DevTools中,无需安装任何扩展。

I integrated chrome logger to my PHP script tested with Chrome and made sure it is working. 我将chrome logger集成到我用Chrome测试过的PHP脚本中并确保它正常工作。 But on Firefox Dev Tools nothing appears on the console . 但是在Firefox Dev Tools上没有出现在控制台上 I checked the headers for X-ChromeLogger-Data. 我检查了X-ChromeLogger-Data的标题。 Encoded data is passed successfully. 编码数据成功传递。

Any one have an idea for solution? 任何人都有解决方案的想法?

For reference developer.mozilla.org/en-US/docs/Tools/Web_Console/Console_messages#Server 供参考developer.mozilla.org/en-US/docs/Tools/Web_Console/Console_messages#Server

Tested with Firefox Developer Edition 56.0b3 and ChromePhp 4.1.0 (Chrome logger php script) 使用Firefox Developer Edition 56.0b3和ChromePhp 4.1.0(Chrome logger php脚本)测试

EDIT: There is something strange. 编辑:有一些奇怪的事情。 There 2 different Developer Tools, One opens with F12 and there are no server tab, and the other opens via Tools>Web Developer menu 有两个不同的开发人员工具,一个打开F12,没有服务器选项卡,另一个通过工具> Web开发人员菜单打开

Server Tab displays nothing about chrome logger 服务器选项卡不显示有关chrome logger的信息

Screen Shots are here: 屏幕截图在这里:

服务器选项已启用

两个不同的工具箱

As of 2017, firebug and hence firephp has been disabled. 截至2017年,萤火虫和firephp已被禁用。

I wrote some little modifications to the chromephp tool to allow seamless migration from firephp to chromephp for debuging via the console. 我对chromephp工具做了一些修改,允许从firephp无缝迁移到chromephp,以便通过控制台进行debuging。

This article explains in clear easy steps 本文以简单明了的步骤解释

https://medium.com/@kudehinbuoluwaponle/migrate-from-firephp-to-chromephp-in-5-minutes-without-breaking-existing-code-e4afd1b28c5c https://medium.com/@kudehinbuoluwaponle/migrate-from-firephp-to-chromephp-in-5-minutes-without-breaking-existing-code-e4afd1b28c5c

As an addition to the details in the article, you don't need to switch to chrome browser, You can also view the logs via the server tab of the firefox web console 作为本文详细信息的补充,您无需切换到chrome浏览器,也可以通过firefox Web控制台的服务器选项卡查看日志

With Firefox 57, aka Firefox Quantum, it looks like server logs from ChromePhp no longer work. 使用Firefox 57,又名Firefox Quantum,看起来ChromePhp的服务器日志不再有效。

QuantumPHP is an alternative. QuantumPHP是另一种选择。 With this tool, the server log and JavaScript log both appear under "console". 使用此工具,服务器日志和JavaScript日志都显示在“控制台”下。

https://github.com/frankforte/quantumphp https://github.com/frankforte/quantumphp

Further to Kudehinbu's work, and my own work, ie refactoring the QuantumPHP class provided https://github.com/frankforte/quantumphp , to give developers a more seamless approach and migration process from FirePHP, I may also add that unlike FirePHP, the client-side rendering will not go over a laconic [object Object] when an object is part of the arguments to the info() , warn() or error() method. 继Kudehinbu的工作,以及我自己的工作,即重构QuantumPHP类提供了https://github.com/frankforte/quantumphp ,为开发人员提供了一个更加无缝的方法和FirePHP的迁移过程,我也可以补充说,与FirePHP不同,当对象是info()warn()error()方法的参数的一部分时,客户端呈现不会超过简洁的[object Object]。

To develop an object exhaustively, like FirePHP did, you may want to transform $args using print_r() or var_export() , either before the call to an output method of the QuantumPHP class, or better, as a private/protected transformer within the class itself. 要像FirePHP那样详尽地开发一个对象,你可能想要在调用QuantumPHP类的输出方法之前使用print_r()var_export()转换$ args ,或者更好,作为一个私有/受保护的变换器。阶级本身。

protected function resolveObjectArgs(array &$args)
{
    array_walk($args, function(&$value, $key) {
        if (is_array($value)) {
            $value = print_r($value, true);
        }
        else if(is_object($value)) {
            $value = var_export($value, true);
        }
        else return;
    });
}

Thus calling this transformer within an output method: 因此在输出方法中调用此转换器:

public function info()
{
    $args = func_get_args();
    $this->resolveObjectArgs($args); // <== this is the line to add to the existing code
    return $this->_log(self::INFO, $args);
}

Note that following my refactoring, info() is now public and no more public static , since I decided to use the object context. 请注意,在我的重构之后, info()现在是公共的 ,不再是公共静态的 ,因为我决定使用对象上下文。

Finally, taking advantage of the public context , you may want to add a destructor: 最后,利用公共上下文 ,您可能想要添加析构函数:

public function __destruct()
{
    $this->send();
}

thus saving from explicitly calling the send method systematically after your PHP script's last call to a QuantumPHP method. 因此,在PHP脚本最后一次调用QuantumPHP方法后,可以系统地显式调用send方法。

Example of client-side use: 客户端使用示例:

 $QPHP = QuantumPHP::getInstance(); $Obj = new MyOwnObject(); $QPHP->info($Obj); // will eventually output a detailed structure of your object // send() gets called magically at the end of the page! 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM