[英]Xdebug laravel artisan commands
我經常使用 xdebug 來調試應用程序,我已經構建了一個 laravel 應用程序,該應用程序需要上傳 csv 將數據插入數據庫並將 ID 插入作業隊列。
我編寫了一個通過 cron 運行的工匠命令,然后對這些數據做一些事情。
Xdebug 適用於通過瀏覽器訪問該站點,但從 cli 運行時它不會中斷斷點。
我運行 php5-fpm。 我的文件/etc/php5/fpm/php.ini
和/etc/php5/cli/php/ini
都包含以下設置:
zend_extension=/usr/lib/php5/20121212/xdebug.so
xdebug.remote_enable = 1
xdebug.idekey = 'dev_docker'
xdebug.remote_autostart = 1
xdebug.remote_connect_back = {{my host ip}}
xdebug.remote_port = 9000
xdebug.remote_handler=dbgp
然后我運行工匠命令
php artisan jobqueue::process --batch-size=10 --sleep=10
我知道命令正在運行,因為 ->info('text') 顯示在終端中
有人知道我錯過了什么嗎?
也許這會幫助某人。
簡而言之,我遇到了同樣的問題,但我對接受的答案沒有運氣。 我的解決方案是從命令行運行它:
php -dxdebug.remote_enable=1 -dxdebug.remote_autostart=on -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=127.0.0.1 artisan my:command
如果您使用的是 XDebug 版本 3,請嘗試:
php -dxdebug.mode=debug -dxdebug.client_host=host.docker.internal -dxdebug.client_port=9003 -dxdebug.start_with_request=yes artisan your:command
我讓它使用 remote_autostart=1 並將 PHP_IDE_CONFIG 環境變量設置為“serverName=localhost”。 localhost 是 PHPStorm 中服務器配置的名稱。 現在,當我運行 php artisan 時,我可以在常規斷點處中斷。
讓我更清楚:)
如果你有 xdebug 使用 PHPStorm 和常規請求,這就是你應該做的讓它與命令行 php (artisan) 一起工作。
您已經在 PHPStorm 中配置了路徑,因此它知道應該向您顯示帶有斷點的文件。 這些路徑在服務器下配置(首選項 -> 語言和框架 -> PHP -> 服務器)。
該服務器的名稱應該是 PHP_IDE_CONFIG 環境變量中的 serverName 值。
根據xdebug.remote_connect_back文檔,它使用$_SERVER['REMOTE_ADDR']
來獲取調試主機。 我想在 CLI 中你必須使用xdebug.remote_host代替。
如果您使用 vagrant,則可以創建artisandebug
shell 文件。
#!/bin/bash
HOST=10.0.2.2
# xdebug 3
php -dxdebug.mode=debug -dxdebug.start_with_request=yes -dxdebug.client_host=$HOST -dxdebug.client_port=9003 artisan "$@"
# xdebug < 3
# php -dxdebug.remote_autostart=on -dxdebug.remote_connect_back=off -dxdebug.remote_host=$HOST -dxdebug.client_port=9003 artisan "$@"
比使其可執行並運行命令:
chmod +x artisandebug
./artisandebug some:command --there
使用 xdebug 3.1.1 和 docker 進行分析
php
-dxdebug.mode=profile
-dxdebug.client_host=IP_SERVICE_WITH_PHP
-dxdebug.client_port=XDEBUG_CLINT_PORT
-dxdebug.start_with_request=yes
-dxdebug.output_dir=/tmp
artisan ARTISAN_COMMAND
例子
php -dxdebug.mode=profile -dxdebug.client_host=172.19.0.3 -dxdebug.client_port=9003 -dxdebug.start_with_request=yes -dxdebug.output_dir=/tmp artisan help
php -dxdebug.mode=debug -dxdebug.client_host=localhost -dxdebug.client_port=9003 -dxdebug.start_with_request=yes artisan ARTISAN_COMMAND
另一種方法是:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.