溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

phpstorm debug工具yasd怎么用

發(fā)布時(shí)間:2022-01-17 16:21:56 來(lái)源:億速云 閱讀:720 作者:柒染 欄目:軟件技術(shù)

phpstorm debug工具yasd怎么用,針對(duì)這個(gè)問題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問題的小伙伴找到更簡(jiǎn)單易行的方法。

平常在開發(fā)中,總會(huì)有一些需要 debug 的時(shí)候,手動(dòng)打斷點(diǎn) var_dump、die 等方式總是耗時(shí)耗力還不優(yōu)雅,這時(shí)候可能會(huì)有人選擇安裝 xdebug 擴(kuò)展,在 phpstorm 中配置 xdebug 來(lái)調(diào)試。

但當(dāng)你需要用到 swoole 框架時(shí),并需要調(diào)試 swoole 框架中代碼時(shí),xdebug 是不能用在 swoole 上的,是和 swoole 有沖突的。

然后我發(fā)現(xiàn)了一款比較好用的,可以兼容 fpm 框架,和 swoole 框架的 debug 調(diào)試工具,yasd.

安裝

1. Mac 上安裝 boots 庫(kù)

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"
;命令行調(diào)試
;yasd.debug_mode=cmd
;遠(yuǎn)程調(diào)試
yasd.debug_mode=remote
;本地開發(fā)地址
yasd.remote_host=127.0.0.1
;本地開發(fā)監(jiān)聽端口
yasd.remote_port=9000

查看擴(kuò)展信息

?  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. 調(diào)試腳本

使用 yasd 調(diào)試腳本,必須要添加 -e 的 php 參數(shù),例如這樣

# 調(diào)試普通php腳本
php -e test.php
# 調(diào)試 laravel 的 command
php -e artisan test
# 調(diào)試 hyperf 框架
php -e bin/hyperf start

配置 phpstorm

1. 配置 phpstorm 監(jiān)聽 9000 端口


2. 點(diǎn)擊 phpstorm 右上角的電話圖標(biāo)啟動(dòng)監(jiān)聽


3. 測(cè)試 debug 調(diào)試

在 Laravel 中隨便寫一個(gè) test command

php -e artisan test

到這里就已經(jīng)成功了

調(diào)試 Hyperf 框架

上面說(shuō)了在 fpm 中調(diào)試,接下來(lái)說(shuō)一下在 Hyperf 框架中如何調(diào)試

需要注意的幾點(diǎn)

1、在 Hyperf 中使用需要將 config.php 中的 scan_cacheable 參數(shù)設(shè)置為 true,該參數(shù)為是否掃描代理類,若設(shè)置為 true,則每次啟動(dòng)都會(huì)直接掃描緩存代理類,而不是重新掃描在生成代理類。

設(shè)置為 true 后需要注意,每次修改代碼需要手動(dòng)生成代理類,composer dump-autoload -o,然后在啟動(dòng)。

或者直接在代理類中修改代碼,當(dāng) debug 結(jié)束后,再將代理類中的代碼復(fù)制到真實(shí)類中。

代理類生成路徑在 runtime/container/proxy

2、在 Hyperf 框架中如果使用到了 Swoole Server,需要將 worker_num 設(shè)置為 1 否則斷點(diǎn)可能不會(huì)生效。該參數(shù)在 server.php 中。

剩下的調(diào)試就和上面講的沒什么區(qū)別了。

關(guān)于phpstorm debug工具yasd怎么用問題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注億速云行業(yè)資訊頻道了解更多相關(guān)知識(shí)。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI