php

phpenv 开启debug 调试之路

梦浪的小虾米
2022-03-05 / 0 评论 / 3,998 阅读 / 正在检测是否收录...

前言

我没用过 debug,也不想用 debug.毕竟静态代码分析一绝。。。

然而事实是:太卷了,不会 debug 出去都不好意思说自己是写 PHP 的(其实是面试被嘲笑了)。
于是今天来用用debug,当一波大佬。

背景环境

window 11
phpenv 8
php 7.4
nginx
vscode

目的

在 vscode 上使用 php debug 进行调试

安装教程:

https://blog.51cto.com/u_15311900/3179913
安装教程大同小异

遇到的问题

核心问题:debug 死活无法命令断点

phpenv 原始配置如下

[Redis]
extension = php_redis.dll
[Xdebug]
;zend_extension = xdebug.dll
;xdebug.remote_enable = 1
;xdebug.remote_autostart = 1
; xdebug.remote_host = localhost
; xdebug.remote_port = 9100

按照网上要去改为

[Redis]
extension = php_redis.dll
[Xdebug]
zend_extension = xdebug.dll
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
; xdebug.remote_host = localhost
; xdebug.remote_port = 9100

结果发现死活不行。

因为没有用过 xdebug,看了网上有说法

  1. 是需要打开浏览器访问地址,然后地址会自动卡住。
    试了一下,卡个锤子,丝滑结束。
  2. vscode 几张模糊教程图,
    结果没搞懂怎么出来的

我也遇到这个错误:
https://blog.csdn.net/tayutayu123/article/details/109211342

文中提到的测试版本地址为:https://xdebug.org/wizard (作者个坑不给出来,真特么蛋疼)

打算按照上述的地址试下的,临机一动,有了一个想法:
因为我用的是 phpenv,phpenv自带了各种拓展,所以 xdebug 配置文件应该是正确的。那么肯定是我的配置文件写的不对,然后通过版本检测后得出

# Instructions
1. Download php_xdebug-3.1.3-7.4-vc15-nts-x86_64.dll
2. Move the downloaded file to ext, and rename it to php_xdebug.dll
3. Update C:\phpEnv\php\php-7.4\php.ini to have the line:
4. zend_extension = xdebug
Restart the webserver

通过观察上述配置可以得知

  1. 把配置文件改名为 php_xdebug.dll 并放到 ext 。这里和我一致,不需要动
  2. zend_extension = xdebug 说明我在配置里面只需要写 xdebug 就行了,而不是写 xdebug.dll

重新打开 vscode 。测试一波,ok ,终于得到对应的图片了

鸣谢

https://blog.csdn.net/tayutayu123/article/details/109211342
https://blog.51cto.com/u_15311900/3179913
https://xdebug.org/wizard

0

评论 (0)

取消