Xdebug laravel artisan 命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33564826/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:39:05  来源:igfitidea点击:

Xdebug laravel artisan commands

phplaravelcommand-line-interfacexdebugartisan

提问by James Kirkby

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 运行的 artisan 命令,然后对这些数据做一些事情。

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. My files /etc/php5/fpm/php.iniand /etc/php5/cli/php/iniboth contain the following settings:

我运行 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

I then run the artisan command

然后我运行 artisan 命令

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?

有谁知道我错过了什么?

采纳答案by Furgas

According to xdebug.remote_connect_backdocumentation it's using $_SERVER['REMOTE_ADDR']to get debugging host. I guess that in CLI you must use xdebug.remote_hostinstead.

根据xdebug.remote_connect_back文档,它$_SERVER['REMOTE_ADDR']用于获取调试主机。我想在 CLI 中你必须使用xdebug.remote_host代替。

回答by boroboris

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

回答by Pepijn

I got it working with remote_autostart=1 and setting the PHP_IDE_CONFIG environment variable to "serverName=localhost". localhost is the name of your server config in PHPStorm. Now when I run php artisan I can break at the regular breakpoints.

我让它使用 remote_autostart=1 并将 PHP_IDE_CONFIG 环境变量设置为“serverName=localhost”。localhost 是 PHPStorm 中服务器配置的名称。现在,当我运行 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. These paths are configured under a server (Preferences -> Languages & Frameworks -> PHP -> Servers).

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

The name of this server should be the serverName value in the PHP_IDE_CONFIG environment variable.

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