首頁  >  文章  >  開發工具  >  詳細介紹phpstorm debug工具之yasd(超好用)

詳細介紹phpstorm debug工具之yasd(超好用)

WBOY
WBOY轉載
2022-01-17 15:33:155484瀏覽

這篇文章為大家帶來了超好用的phpstorm debug工具,平常在開發中,可能會有人選擇安裝xdebug擴展,在phpstorm中配置xdebug來調試,希望對大家有幫助。

詳細介紹phpstorm debug工具之yasd(超好用)

平常在開發中,總是會有一些需要debug 的時候,手動打斷點var_dump、die 等方式總是耗時耗力還不優雅,這時候可能會有人選擇安裝xdebug 擴展,在phpstorm 中配置xdebug 來調試。

但當你需要用到 swoole 框架時,並且需要調試 swoole 框架中程式碼時,xdebug 是不能用在 swoole 上的,是​​和 swoole 有衝突的。

然後我發現了一個比較好用的,可以相容fpm 框架,和swoole 框架的debug 偵錯工具,yasd.

##安裝

#1. Mac 上安裝boots 庫#

brew install boost

2. 從Github 下載yasd 原始碼

git clone https://github.com/swoole/yasd.git

3. 編譯安裝yasd#

cd yasd
phpize --clean && \
phpize && \
./configure && \
make clean && \
make && \
make install

4. 修改php.ini#

zend_extension="yasd.so"
;命令行调试
;yasd.debug_mode=cmd
;远程调试
yasd.debug_mode=remote
;本地开发地址
yasd.remote_host=127.0.0.1
;本地开发监听端口
yasd.remote_port=9000

查看擴充資訊

➜  yasd php --ri yasd
yasd
Yasd => enabled
Author => codinghuang <codinghuang@qq.com>
Version => 0.3.9-alpha
Built => Jan 15 2022 14:09:47
Directive => Local Value => Master Value
yasd.breakpoints_file => no value => no value
yasd.debug_mode => remote => remote
yasd.remote_host => 127.0.0.1 => 127.0.0.1
yasd.remote_port => 9000 => 9000
yasd.depth => 1 => 1
yasd.log_level => -1 => -1
yasd.max_executed_opline_num => 0 => 0
yasd.init_file => no value => no value
yasd.open_extended_info => 0 => 0
xdebug.coverage_enable => 1 => 1
xdebug.profiler_enable => 1 => 1
xdebug.remote_autostart => 1 => 1
xdebug.remote_connect_back => 0 => 0
xdebug.remote_mode => req => req
xdebug.idekey => hantaohuang => hantaohuang

5. 偵錯腳本

使用yasd 偵錯腳本,必須新增- e 的php 參數,例如這樣

# 调试普通php脚本
php -e test.php
# 调试 laravel 的 command
php -e artisan test
# 调试 hyperf 框架
php -e bin/hyperf start

設定phpstorm

1. 設定phpstorm 監聽9000 連接埠

詳細介紹phpstorm debug工具之yasd(超好用)

#2. 點選phpstorm 右上角的電話圖示啟動監聽

詳細介紹phpstorm debug工具之yasd(超好用)

3.測試debug 調試

在Laravel 中隨便寫一個test command

php -e artisan test

詳細介紹phpstorm debug工具之yasd(超好用)

到這裡就已經成功了

#調試Hyperf 框架

上面說了在fpm 中調試,接下來說一下在Hyperf 框架中如何調試

需要注意的幾點

1、在Hyperf 中使用需要將config.php 中的scan_cacheable 參數設為true,該參數為是否掃描代理類,若設為true,則每次啟動都會直接掃描快取代理類,而不是重新掃描在產生代理類別。

設定為 true 後需要注意,每次修改程式碼需要手動產生代理類,composer dump-autoload -o,然後在啟動。

或直接在代理類別中修改程式碼,當 debug 結束後,再將代理類別中的程式碼複製到真實類別中。

代理程式類別產生路徑在 runtime/container/proxy

2、在 Hyperf 框架中如果使用到了 Swoole Server,則需要將 worker_num 設為 1 否則斷點可能不會生效。該參數在 server.php 中。

剩下的調試就跟上面講的沒什麼差別了。

推薦學習:《

phpstorm教學

以上是詳細介紹phpstorm debug工具之yasd(超好用)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:learnku.com。如有侵權,請聯絡admin@php.cn刪除