简体   繁体   English

Xdebug laravel 工匠命令

[英]Xdebug laravel artisan commands

I regularly use xdebug to debug applications, I've built a laravel application that takes an upload of a csv inserts the data to the database and the ids to a job queue.我经常使用 xdebug 来调试应用程序,我已经构建了一个 laravel 应用程序,该应用程序需要上传 csv 将数据插入数据库并将 ID 插入作业队列。

I've written an artisan command to be run via cron to then do something with this data.我编写了一个通过 cron 运行的工匠命令,然后对这些数据做一些事情。

Xdebug works for accessing the site via the browser, but its not breaking on breakpoints when ran from cli. Xdebug 适用于通过浏览器访问该站点,但从 cli 运行时它不会中断断点。

I run php5-fpm.我运行 php5-fpm。 My files /etc/php5/fpm/php.ini and /etc/php5/cli/php/ini both contain the following settings:我的文件/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

I then run the artisan command然后我运行工匠命令

php artisan jobqueue::process --batch-size=10 --sleep=10

I know the command is running as ->info('text') is displayed in the terminal我知道命令正在运行,因为 ->info('text') 显示在终端中

Anyone know what I'm missing?有人知道我错过了什么吗?

Maybe this will help someone.也许这会帮助某人。

In short I had the same problem but I didn't have luck with accepted answer.简而言之,我遇到了同样的问题,但我对接受的答案没有运气。 My solution is to run this from the command line:我的解决方案是从命令行运行它:

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

I got it working with remote_autostart=1 and setting the PHP_IDE_CONFIG environment variable to "serverName=localhost".我让它使用 remote_autostart=1 并将 PHP_IDE_CONFIG 环境变量设置为“serverName=localhost”。 localhost is the name of your server config in PHPStorm. localhost 是 PHPStorm 中服务器配置的名称。 Now when I run php artisan I can break at the regular breakpoints.现在,当我运行 php artisan 时,我可以在常规断点处中断。

Let me be more clear :)让我更清楚:)

If you've got xdebug working with PHPStorm and regular requests this is what you should do to get it working with command line php (artisan).如果你有 xdebug 使用 PHPStorm 和常规请求,这就是你应该做的让它与命令行 php (artisan) 一起工作。

You have configured paths in PHPStorm so it knows which file it should show you with the breakpoints.您已经在 PHPStorm 中配置了路径,因此它知道应该向您显示带有断点的文件。 These paths are configured under a server (Preferences -> Languages & Frameworks -> PHP -> Servers).这些路径在服务器下配置(首选项 -> 语言和框架 -> PHP -> 服务器)。

The name of this server should be the serverName value in the PHP_IDE_CONFIG environment variable.该服务器的名称应该是 PHP_IDE_CONFIG 环境变量中的 serverName 值。

According to xdebug.remote_connect_back documentation it's using $_SERVER['REMOTE_ADDR'] to get debugging host.根据xdebug.remote_connect_back文档,它使用$_SERVER['REMOTE_ADDR']来获取调试主机。 I guess that in CLI you must use xdebug.remote_host instead.我想在 CLI 中你必须使用xdebug.remote_host代替。

If you use vagrant, than you can create artisandebug shell file.如果您使用 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  "$@"

Than make it executable and run command :比使其可执行并运行命令:

chmod +x artisandebug

./artisandebug some:command --there

For profiling with xdebug 3.1.1 and docker使用 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

Example例子

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

An alternative approach would be to:另一种方法是:

  1. First start debugger首先启动调试器
  2. Run: php artisan tinker运行:php artisan tinker
  3. Within tinker run: Artisan::call('your-command');在修补程序运行中: Artisan::call('your-command');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM