如何自动删除 FirePHP 的调试语句?

发布于 2024-11-18 19:14:05 字数 212 浏览 8 评论 0原文

FirePHP 要求我在每个 .php 页面上添加调试函数调用:

require_once('FirePHPCore/FirePHP.class.php');
ob_start();

这在我的本地计算机上不是问题。但我想当我的代码在现实世界中运行时删除/禁用它们。

是否有任何“调试模式”变量可以禁用它们或有工具可以删除它们?

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

require_once('FirePHPCore/FirePHP.class.php');
ob_start();

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

沉鱼一梦 2024-11-25 19:14:05

注意:如果您删除了 FirePHP 包含调用,但代码中仍然有 FirePHP 日志记录调用,您将收到致命错误!

正确的解决方案是禁用FirePHPCore 0.3

$firephp->setEnabled(false);

请参阅API 参考了解更多信息。

应用程序/网站中的所有页面/脚本都应在执行其他操作之前调用中央引导文件。上面的代码应该位于此引导程序文件中,这将允许您在部署时轻松禁用整个应用程序的 FirePHP

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);
}

仅供参考,如果使用 FirePHP 1.0 仅在检测到授权客户端时才会发送日志消息,从而无需代码 多于。

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.

醉南桥 2024-11-25 19:14:05

只需定义一个常量

define('IS_PRODUCTION', false);

并稍后使用它:

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

Just define a constant

define('IS_PRODUCTION', false);

and use it later:

if (!IS_PRODUCTION) {
    require_once('FirePHPCore/FirePHP.class.php');
    ...
}
情归归情 2024-11-25 19:14:05

卡多恩的后续行动:
如果在您的框架中,FirePHP 是可选安装(插件、插件,..),有人最终可能会完全禁用或完全卸载,您可能会考虑检查您的框架核心<中的 FirePHP 类或函数的可用性/em> 通过 class_exists()function_exists(),如果 FirePHP 无法访问,请定义替代函数。这样,您可以避免致命错误,并最终提供一些反馈/输出,例如“FirePHP 不可用”。

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"..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文