Xdebug laravel artisan commands


Xdebug laravel artisan commands

我经常使用xdebug来调试应用程序,我已经构建了一个laravel应用程序,它可以上传csv,将数据插入数据库,将id插入作业队列。

我已经编写了一个通过cron运行的artisan命令,然后对这些数据进行处理。

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

我知道命令正在运行,因为->信息("文本")显示在终端中

有人知道我缺了什么吗?

也许这会对某人有所帮助。

简而言之,我也有同样的问题,但我并没有幸运地得到公认的答案。我的解决方案是从命令行运行:

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

更新2023-08

我使用的是xDebug v3.2.1,php v8.2。如果您不想每次都写那些长命令,请将这些行添加到xdebug.ini文件中。/etc/php/8.2/modes-available/xdebug.ini

zend_extension=xdebug.so
xdebug.mode=debug
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
xdebug.start_with_request=yes

我使用remote_autostart=1并将PHP_IDE_CONFIG环境变量设置为"serverName=localhost"。localhost是PHPStorm中服务器配置的名称。现在,当我运行php-artisan时,我可以在常规断点处中断。

让我更清楚一点:)

如果您让xdebug处理PHPStorm和常规请求,那么您应该这样做才能让它处理命令行php(artisan)。

您已经在PHPStorm中配置了路径,这样它就知道应该向您显示带有断点的文件。这些路径是在服务器下配置的(首选项->语言和框架->PHP->服务器)。

此服务器的名称应该是PHP_IDE_CONFIG环境变量中的serverName值。

如果使用流浪,则可以创建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.remote_connect_back文档,它使用$_SERVER['REMOTE_ADDR']来获取调试主机。我想在CLI中,您必须使用xdebug.remote_host。

用于使用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

另一种方法是:

  1. 首次启动调试器
  2. 运行:php artisan tinker
  3. 在修补程序运行中:Artisan::call('your-command')