Zortext
Zortext

Reputation: 639

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.

Checked the documentation I found this information:

Firebug extensions like FirePHP allow to log server-side messages to the Firebug console. This functionality is already integrated into the DevTools using the ChromeLogger protocol and doesn't require any extensions to be installed.

I integrated chrome logger to my PHP script tested with Chrome and made sure it is working. But on Firefox Dev Tools nothing appears on the console. I checked the headers for 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

Tested with Firefox Developer Edition 56.0b3 and ChromePhp 4.1.0 (Chrome logger php script)

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

Server Tab displays nothing about chrome logger

Screen Shots are here:

Server option enabled

Two different Tool Boxes

Upvotes: 1

Views: 2680

Answers (3)

Fabien Haddadi
Fabien Haddadi

Reputation: 2080

Further to Kudehinbu's work, and my own work, i.e 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.

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.

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.

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.

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!

Upvotes: 1

Frank Forte
Frank Forte

Reputation: 2190

With Firefox 57, a.k.a. Firefox Quantum, it looks like server logs from ChromePhp no longer work.

QuantumPHP is an alternative. With this tool, the server log and JavaScript log both appear under "console".

https://github.com/frankforte/quantumphp

Upvotes: 1

Kudehinbu Oluwaponle
Kudehinbu Oluwaponle

Reputation: 1145

As of 2017, firebug and hence firephp has been disabled.

I wrote some little modifications to the chromephp tool to allow seamless migration from firephp to chromephp for debuging via the console.

This article explains in clear easy steps

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

Upvotes: 1

Related Questions