温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Yii2 HOW-TO(3):调试工具yii2-debug和Xdebug(失败)

发布时间:2020-07-26 09:15:30 来源:网络 阅读:1887 作者:googlingman 栏目:web开发

Yii 1.0时代使用CWebLogRoute

在早期Yii 1.0时代,借助于CWebLogRoute可以在指定Web页面中输入日志信息。因为现在广泛使用Yii 2.X,所以此方式使用说明不再详述。有兴趣的读者可参考参考资料1.

使用yii2-debug

简介

yii2-debug调试工具当属Yii 2.0时代调试PHP代码的首选。此扩展为 Yii 2 应用程序提供了一个调试器。当使用此扩展时, 每个页面的底部将出现一个调试器工具栏。此扩展还提供了 一系列独立的页面来显示更详细的调试信息。

工具栏显示当前打开的页面信息,此时调试器可以用来分析你以前 所收集的数据(例如,确认变量的值)。

在这些工具中您可以:


  • 通过工具栏可快速获取框架版本,PHP 版本,响应状态,当前控制器和动作,性能信息和 更多;
  • 浏览应用程序和 PHP 配置;
  • 查看请求数据,请求和响应头,会话数据,和环境变量;
  • 查看,搜索,和过滤日志;
  • 查看任意的分析结果;
  • 查看页面执行的数据库查询;
  • 查看应用程序发送的电子邮件。

所有这些信息可按要求提供,让您更好的重新查看过去的请求信息。

安装、配置和使用

本文后面引用4中简洁、准确记录了Yii2-debug的使用方法;在此不再赘述。

刚开始Yii开发时,Yii2-debug调试面板并不显示。参考下图,其中是一个简单的视图。
Yii2 HOW-TO(3):调试工具yii2-debug和Xdebug(失败)

注意到,上图中没有显示调试面板。但是,请注意观察截图右下角的“<”,点击这个符号即可显示Yii2-debug调试面板的最小缩图,如下:
Yii2 HOW-TO(3):调试工具yii2-debug和Xdebug(失败)

点击面板上某个内容即可显示大面板和详细信息,如下图所示:
Yii2 HOW-TO(3):调试工具yii2-debug和Xdebug(失败)
至此,恕不再详述。如果您熟悉Firefox下的Firebug开发工具,相信你这个工具你一定喜欢,相当棒!

安装与使用Xdebug失败

重要声明

其实,这几句是我特别在此插入的。因为,我的MacOS High Sierra(10.13.6)中安装的XAMPP版本太高了(约上一个月安装的),对应的PHP版本是7.2.9。因此,有一个奇怪的结果是:目前使用在网络及官方建议的“pecl install xdebug”方式安装Xdebug失败............

注意:我花费了近两天时间GOOGLE了大量资料,最后结论是针对PHP版本7.2.9,尚无法安装XDEBUG支持。可能这个结论有所变动,或者过段时间“pecl install xdebug”命令官方会提供支持,我会进一步修改此结论。因此,如果有读者正想在您的MAC下XAMPP中加入XDEBUG支持,请使用版本较低的!!!后面的内容目前不再需要浪费您的阅读时间了。

Xdebug是调试PHP开发中必须安装的调试工具——单补调试,断点跟踪等,所以这一些都不必说了。我安装的是xampp-osx-7.2.9-0-installer.dmg,但是值得注意的是:在比较新的XAMPP中并没有内置Xdebug这个内置扩展。需要手动安装。

安装PECL

这是引用文6(官方网站)中推荐的MAC上的安装方法。因此首先需要安装PECL。

PECL(The PHP Extension Community Library)是 PHP 扩展的存储库,为 PHP 所有的扩展提供提供托管和下载服务。

通过 PEAR(PHP Extension and Application Repository)的 Package Manager 的安装管理方式,可以对 PECL 扩展进行下载和安装。

1. 下载 PEAR

使用MAC内置的命令行工具 curl 命令下载即可:
curl -O https://pear.php.net/go-pear.phar

2. 安装 PEAR

必须是使用 sudo 授权进行安装,如下:
sudo php -d detect_unicode=0 go-pear.phar

安装过程需要进行简单的配置,如下:

Below is a suggested file layout for your new PEAR installation. To
change individual locations, type the number in front of the
directory. Type 'all' to change all of them or simply press Enter to
accept these locations.

  1. Installation base ($prefix) : /usr
  2. Temporary directory for processing : /tmp/pear/install
  3. Temporary directory for downloads : /tmp/pear/install
  4. Binaries directory : /usr/bin
  5. PHP code directory ($php_dir) : /usr/share/pear
  6. Documentation directory : /usr/docs
  7. Data directory : /usr/data
  8. User-modifiable configuration files directory : /usr/cfg
  9. Public Web Files directory : /usr/www
    1. System manual pages directory : /usr/man
    2. Tests directory : /usr/tests
    3. Name of configuration file : /private/etc/pear.conf

1-12, 'all' or Enter to continue:

输入 1,将安装根目录修改为 /usr/local/pear;
输入 4,将命令安装到 /usr/local/bin 目录;
其它选项默认即可,一路回车。

也就是说,在上面【:】后面输入1,然后在随后的提示行中把安装根目录的位置修改为/usr/local/pear,再输入4来修改命令安装位置,此时输入/usr/local/bin。之后,一路回车下来,即可完美安装PEAR了。

3. 测试安装结果

输入命令行:pear version,我的电脑结果输出如下:


PEAR Version: 1.10.5
PHP Version: 7.1.16
Zend Engine Version: 3.1.0
Running on: Darwin undefined.hostname.localhost 17.7.0 Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018; root:xnu-4570.71.2~1/RELEASE_X86_64 x86_64


使用PECL安装Xdebug

理论上是使用如下命令:
pecl install xdebug
但是,出现如下错误提示:
Password:
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
downloading xdebug-2.6.1.tgz ...
Starting to download xdebug-2.6.1.tgz (283,961 bytes)
.................................................done: 283,961 bytes
79 source files, building
running: phpize
Configuring for:
PHP Api Version: 20160303
Zend Module Api No: 20160303
Zend Extension Api No: 320160303
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

ERROR: `phpize' failed

于是,先使用brew安装了autoconf:
brew install autoconf

正式安装Xdebug

使用如下命令:
sudo pecl install xdebug

出现很长的跨屏幕提示,大致意思是下载后要重新编译一下才得到xdebug.so文件。

路径问题

注意,上面命令编译后的xdebug.so所在的位置要搞清楚。我的机器上是生成到了路径/usr/lib/php/extensions/no-debug-non-zts-20160303。

其他(略)

引用

1.https://blog.csdn.net/calm_thinker/article/details/51452695,《yii 如何使用 CWebLogRoute 记录和调试变量》。2.https://www.yiiframework.com/doc/api/1.1/CWebLogRoute
3.https://github.com/yiisoft/yii2-debug/blob/master/docs/guide-zh-CN/README.md
4.https://github.com/yiisoft/yii2-debug/blob/master/docs/guide-zh-CN/installation.md。
5.https://blog.csdn.net/json_vip/article/details/79324524
6.https://xdebug.org/docs/install
7.https://medium.com/@romaninsh/install-php-7-2-xdebug-on-macos-high-sierra-with-homebrew-july-2018-d7968fe7e8b8
br/>2.https://www.yiiframework.com/doc/api/1.1/CWebLogRoute
3.https://github.com/yiisoft/yii2-debug/blob/master/docs/guide-zh-CN/README.md
4.https://github.com/yiisoft/yii2-debug/blob/master/docs/guide-zh-CN/installation.md。
5.https://blog.csdn.net/json_vip/article/details/79324524
6.https://xdebug.org/docs/install
7.https://medium.com/@romaninsh/install-php-7-2-xdebug-on-macos-high-sierra-with-homebrew-july-2018-d7968fe7e8b8

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI