开发者

How to automatically remove debug statements for FirePHP?

FirePHP asks me to add debug function call on every .php page:

require_once('FirePHPCore/FirePHP.class.php');
ob_start(开发者_JS百科);

It ist't a problem on my local machine. But I want to remove/disable them when my code is working in real world.

Is there any "debug mode" variable to disable them or tool to remove them?


NOTE: If you remove the FirePHP include call but still have FirePHP logging calls in your code you will get a fatal error!

The proper solution is to disable FirePHPCore 0.3:

$firephp->setEnabled(false);

See API reference for more information.

All pages/scripts in your application/website should call a central bootstrap file before doing anything else. The code above should be in this bootstrap file which will allow you to easily disable FirePHP for the entire application when deployed:

bootstrap.php ~

ob_start();
require_once('FirePHPCore/FirePHP.class.php');
$firephp = FirePHP::getInstance(true);
// always disable FirePHP first - best practice
$firephp->setEnabled(false);
// only enable if in dev environment - best practice
if ($isDevMode) {
    $firephp->setEnabled(true);
}

FYI, If using FirePHP 1.0 logging messages will only be sent if an authorized client is detected eliminating the need for the code above.


Just define a constant

define('IS_PRODUCTION', false);

and use it later:

if (!IS_PRODUCTION) {
    require_once('FirePHPCore/FirePHP.class.php');
    ...
}


followup to cadorn: If in your framework FirePHP is an optional install (addon,plugin,..) someone could eventually dissable or uninstall completely, you might consider to check FirePHP class or functions availability in your frameworks core via class_exists() or function_exists(), and in case FirePHP is out of reach, define subsititute functions. That way, you can avoid fatals, and eventually give some feedback/ouput alike "FirePHP not available"..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜