php PhpStorm 未接收 xdebug 连接:PhpStorm 事件日志:无法评估表达式 'isset($_SERVER['PHP_IDE_CONFIG'])'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29035705/
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-08-26 00:12:45  来源:igfitidea点击:

PhpStorm is not receiving xdebug connections : PhpStorm event log : Cannot evaluate expression 'isset($_SERVER['PHP_IDE_CONFIG'])'

phpphpstormxdebug

提问by Osama Salama

I configured everything for PhpStorm and xdebug to work, I'm running Ubuntu 14.04.

我为 PhpStorm 和 xdebug 配置了一切,我正在运行 Ubuntu 14.04。

the connection back to the IDE is not established, and I get this in the IDE event Log

没有建立回 IDE 的连接,我在 IDE 事件日志中得到了这个

Cannot accept external Xdebug connection: Cannot evaluate expression 'isset($_SERVER['PHP_IDE_CONFIG'])' – Osama Salama 13 mins ago

无法接受外部 Xdebug 连接:无法评估表达式 'isset($_SERVER['PHP_IDE_CONFIG'])' – Osama Salama 13 分钟前

I'll put together configuration values I configured in various places. As I can't find out where is the problem

我会把我在不同地方配置的配置值放在一起。因为我不知道问题出在哪里

php.ini

配置文件

zend_extension = /usr/lib/php5/20121212/xdebug.so
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_connect_back = 1
xdebug.remote_autostart = 1
xdebug.remote_log=xxx/xdebug.log
xdebug.IDE_key=PHPSTORM

PHP info

PHP信息

xdebug

调试

xdebug support  enabled
Version 2.3.1
IDE Key PHPSTORM

Supported protocols Revision
DBGp - Common DeBuGger Protocol $Revision: 1.145 $

Directive   Local Value Master Value

xdebug.auto_trace   Off Off
xdebug.cli_color    0   0
xdebug.collect_assignments  Off Off
xdebug.collect_includes On  On
xdebug.collect_params   0   0
xdebug.collect_return   Off Off
xdebug.collect_vars Off Off
xdebug.coverage_enable  On  On
xdebug.default_enable   On  On
xdebug.dump.COOKIE  no value    no value
xdebug.dump.ENV no value    no value
xdebug.dump.FILES   no value    no value
xdebug.dump.GET no value    no value
xdebug.dump.POST    no value    no value
xdebug.dump.REQUEST no value    no value
xdebug.dump.SERVER  no value    no value
xdebug.dump.SESSION no value    no value
xdebug.dump_globals On  On
xdebug.dump_once    On  On
xdebug.dump_undefined   Off Off
xdebug.extended_info    On  On
xdebug.file_link_format no value    no value
xdebug.force_display_errors Off Off
xdebug.force_error_reporting    0   0
xdebug.halt_level   0   0
xdebug.idekey   no value    no value
xdebug.max_nesting_level    256 256
xdebug.max_stack_frames -1  -1
xdebug.overload_var_dump    On  On
xdebug.profiler_aggregate   Off Off
xdebug.profiler_append  Off Off
xdebug.profiler_enable  Off Off
xdebug.profiler_enable_trigger  Off Off
xdebug.profiler_enable_trigger_value    no value    no value
xdebug.profiler_output_dir  /tmp    /tmp
xdebug.profiler_output_name cachegrind.out.%p   cachegrind.out.%p
xdebug.remote_autostart On  On
xdebug.remote_connect_back  On  On
xdebug.remote_cookie_expire_time    3600    3600
xdebug.remote_enable    On  On
xdebug.remote_handler   dbgp    dbgp
xdebug.remote_host  127.0.0.1   127.0.0.1
xdebug.remote_log   /home/nautilus/Desktop/xdebug.log   /home/nautilus/Desktop/xdebug.log
xdebug.remote_mode  req req
xdebug.remote_port  9000    9000
xdebug.scream   Off Off
xdebug.show_exception_trace Off Off
xdebug.show_local_vars  Off Off
xdebug.show_mem_delta   Off Off
xdebug.trace_enable_trigger Off Off
xdebug.trace_enable_trigger_value   no value    no value
xdebug.trace_format 0   0
xdebug.trace_options    0   0
xdebug.trace_output_dir /tmp    /tmp
xdebug.trace_output_name    trace.%c    trace.%c
xdebug.var_display_max_children 128 128
xdebug.var_display_max_data 512 512
xdebug.var_display_max_depth    3   3

I also validated the remote debugging env. it's all good.https://www.jetbrains.com/phpstorm/help/validating-the-configuration-of-a-debugging-engine.htmlwhich also came out fine.

我还验证了远程调试环境。都很好。https://www.jetbrains.com/phpstorm/help/validating-the-configuration-of-a-debugging-engine.html也很好。

The last possible resort is the xdebug log file:

最后可能的手段是 xdebug 日志文件:

Log opened at 2015-03-13 14:39:01
I: Checking remote connect back address.
W: Remote address not found, connecting to configured address/port: 127.0.0.1:9000. :-|
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="dbgp://stdin" language="PHP" protocol_version="1.0" appid="4474"><engine version="2.3.1"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2015 by Derick Rethans]]></copyright></init>
<- feature_set -i 1 -n show_hidden -v 1
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="1" feature="show_hidden" success="1"></response>
<- feature_set -i 2 -n max_depth -v 1
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="2" feature="max_depth" success="1"></response>
<- feature_set -i 3 -n max_children -v 100
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="3" feature="max_children" success="1"></response>
<- status -i 4
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="status" transaction_id="4" status="starting" reason="ok"></response>
<- step_into -i 5
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="step_into" transaction_id="5" status="stopping" reason="ok"></response>
<- eval -i 6 -- aXNzZXQoJF9TRVJWRVJbJ1BIUF9JREVfQ09ORklHJ10p
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="eval" transaction_id="6"><error code="5"><message><![CDATA[command is not available]]></message></error></response>
Log closed at 2015-03-13 14:39:01

采纳答案by Buttle Butkus

I had the exact same error in PhpStorm as the OP.

我在 PhpStorm 中遇到了与 OP 完全相同的错误。

This answerto a different question solved the problem for me, but I would like to add more detail in my own answer.

This answerto a different question为我解决了这个问题,但我想在我自己的答案中添加更多细节。

The main issue was improperly loaded xdebug. The server mapping issues mentioned in other answers was not an issue for me.

主要问题是未正确加载 xdebug。其他答案中提到的服务器映射问题对我来说不是问题。

If you load your phpinfo()page and find the xdebug section, and you see this:

如果您加载phpinfo()页面并找到 xdebug 部分,您会看到:

XDEBUG NOT LOADED AS ZEND EXTENSION

XDEBUG 未加载为 Zend 扩展

XDEBUG NOT LOADED AS ZEND EXTENSION

XDEBUG 未加载为 Zend 扩展

Then you have to fix that before you try anything else! But sometimes this can take some work to track down, if you have multiple php.inifiles.

然后你必须先解决这个问题,然后再尝试其他任何事情!但有时这可能需要一些工作来追踪,如果您有多个php.ini文件。

Also in your phpinfo()page, search for "php.ini", (it should be right near the top) and see your "Configuration File (php.ini) Path", and your "Loaded Configuration File". Those are where your xdebug may be loading.

同样在您的phpinfo()页面中,搜索“php.ini”(它应该就在顶部附近)并查看您的“配置文件(php.ini)路径”和“加载的配置文件”。这些是您的 xdebug 可能正在加载的地方。

enter image description here

enter image description here

In my case, I correctly loaded it as a Zend extension in my main configuration file in /usr/local/lib/php.ini, like so:

就我而言,我在 /usr/local/lib/php.ini 的主配置文件中正确地将它加载为 Zend 扩展,如下所示:

zend_extension = "/usr/local/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so"

But in my Loaded Configuration file in /home/someuser/public_html/php.ini, I had it incorrectly loaded like this:

但是在 /home/someuser/public_html/php.ini 中的加载配置文件中,我错误地加载了它,如下所示:

extension=xdebug.so

After fixing that, remote debugging with PhpStorm is working again for me.

修复该问题后,使用 PhpStorm 进行远程调试又对我有用了。

As a side note, the first error I saw in PhpStorm was the exact same one the OP mentions, and here is what it looks like:

作为旁注,我在 PhpStorm 中看到的第一个错误与 OP 提到的完全相同,如下所示:

PhpStorm xdebug server variables error

PhpStorm xdebug server variables error

Cannot accept external Xdebug connection
Cannot evaluate expression 'isset($_SERVER['PHP_IDE_CONFIG'])'

( At first I thought that, because the extension was not loaded properly, PhpStorm was not able to execute PHP code on the server. But now I think PhpStorm only executes php code if you configured an interpreter, which isn't necessary for debugging. For debugging, PhpStorm just needs the xdebug connection and the correct path mappings.)

(一开始我以为是因为扩展没有正确加载,所以PhpStorm无法在服务器上执行PHP代码。但现在我认为如果你配置了解释器,PhpStorm只会执行PHP代码,这不是调试所必需的。对于调试,PhpStorm 只需要 xdebug 连接和正确的路径映射。)

Later, I found the "Command is not available" error in the xdebug log on my server, which led me to the solution.

后来在我服务器上的xdebug日志中发现了“Command is not available”错误,找到了解决办法。

Here, by the way, is what I have in my local php.inifor xdebug:

顺便说一下,这里是我在本地php.ini的 xdebug :

;extension=xdebug.so <- this is the bad line commented!
zend_extension = "/usr/local/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so"

xdebug.remote_enable=true
xdebug.remote_port="9000"
xdebug.profiler_enable=1
xdebug.profiler_output_dir="/tmp/xdebug-someuser/"
xdebug.profile_enable_trigger=1
xdebug.trace_enable_trigger=1
xdebug.idekey="PHPSTORM"
xdebug.remote_log="var/log/xdebug/xlog"

回答by Andrew Boxer

I have recently had the same problem attempting to debug using PHPStormunder nginxand php-fpm, in my case this was not related to the xdebug, nginxor php-fpm config, it was the path mappings in phpstormthat were missing.

最近我有尝试调试使用了同样的问题PHPStormnginxphp-fpm,于我而言这是不相关的xdebugnginx或者php-fpm config,它是在路径映射phpstorm是人失踪。

Initially PHPStormwill notify you when it cannot map a file on the server to a local source file however if it has a mapping to the first files hit ( normally index.phpor some such ) but it cannot map a file used at a later stage ( in my case this was the autoloader in the vendor directory of a project using composer ) then PHPStormwill not be able to debug any further and debugging will stop.

最初PHPStorm会在它无法将服务器上的文件映射到本地源文件时通知您,但是如果它映射到第一个命中的文件(通常index.php或某些此类),但它无法映射稍后使用的文件(在我的情况下)这是使用 composer 的项目的供应商目录中的自动加载器)然后PHPStorm将无法进一步调试并且调试将停止。

In order to rectify this in PHPStormgo to settings/Languages & Frameworks/PHP/Serversand ensure the root of your project is mapped correctly to it's counterpart directory on the server.

为了在PHPStormgo to 中纠正此问题settings/Languages & Frameworks/PHP/Servers并确保您的项目的根目录正确映射到服务器上的对应目录。

PHPStormshould then be able to map all the files in your project and debugging should continue.

PHPStorm然后应该能够映射项目中的所有文件,调试应该继续。

I hope this helps.

我希望这有帮助。

回答by Mage2.PRO

Debugging a file named ?test.php? in IntelliJ IDEA / PhpStorm can leadto the ?Cannot evaluate expression 'isset($_SERVER['PHP_IDE_CONFIG'])'? failure.
Use another name for file.

调试名为 ? 测试.php?在 IntelliJ IDEA/PhpStorm 中会导致? 无法计算表达式“ isset($_SERVER['PHP_IDE_CONFIG'])?失败。
为文件使用另一个名称。

回答by Augustas

Also same error if you missed to set environment variable in docker-compose.ymlfor your workspace configuration:

如果您错过docker-compose.yml为工作区配置设置环境变量,也会出现同样的错误:

workspace: build: environment: - PHP_IDE_CONFIG=${PHP_IDE_CONFIG}

workspace: build: environment: - PHP_IDE_CONFIG=${PHP_IDE_CONFIG}

回答by popstr

I had this problem as well and tried every trick I could find, but nothing worked. For me, debugging works most of the time, but sometimes it just stops working with the message: "Cannot accept external Xdebug connection: Cannot evaluate expression 'isset($_SERVER['PHP_IDE_CONFIG'])'"

我也有这个问题,并尝试了我能找到的所有技巧,但没有任何效果。对我来说,调试大部分时间都有效,但有时它只是停止处理消息:“无法接受外部 Xdebug 连接:无法评估表达式 'isset($_SERVER['PHP_IDE_CONFIG'])'”

So I eventually realized I had a compilation error in my code (misspelled method name - PhpStorm does not always report these things, at least in my setup). As soon as I corrected the error debugging started working again. Maybe this can help someone struggling.

所以我最终意识到我的代码中有一个编译错误(方法名称拼写错误 - PhpStorm 并不总是报告这些事情,至少在我的设置中)。一旦我纠正了错误,调试又开始工作了。也许这可以帮助那些挣扎的人。

Although I still have issues with breakpoints not being hit, I can throw in a "xdebug_break();" line in the code and debugging becomes more reliable. The downside with using xdebug_break instead of breakpoints is (apart from the fact that it's more work than just adding a breakpoint) the local variables not being displayed in the PhpStorm debugger for some reason (only globals are shown). That makes debugging less convenient, but at least I can make it work.

尽管我仍然遇到未命中断点的问题,但我可以抛出“xdebug_break();” 代码中的行和调试变得更加可靠。使用 xdebug_break 而不是断点的缺点是(除了添加断点的工作量更大这一事实之外)由于某种原因,PhpStorm 调试器中未显示局部变量(仅显示全局变量)。这使得调试不太方便,但至少我可以让它工作。

Apparently you can't have everything :) Coming from the Java world, good debugging is just something I have been able to take for granted, but I have now realized how spoiled I have been :)

显然你不能拥有一切:) 来自 Java 世界,良好的调试只是我已经能够认为理所当然的事情,但我现在意识到我被宠坏了 :)

回答by iainp999

For anyone else coming to this issue, there is another potential configuration option that you could be missing.

对于遇到此问题的其他人,您可能会缺少另一个潜在的配置选项。

Make sure that you have correctly configured your server to use the correct path mapping between your local and remote files.

确保您已正确配置服务器以在本地和远程文件之间使用正确的路径映射。

For example, if your site root is mounted locally at /home/foo/www/mysitebut installed on the server at /www/mysitethen you will need to edit your server configuration in PHPStorm to use path mappings (simply enter /www/mysitein the box alongside /home/foo/www/mysite).

例如,如果您的站点根目录安装在本地/home/foo/www/mysite但安装在服务器上,/www/mysite那么您需要在 PHPStorm 中编辑您的服务器配置以使用路径映射(只需/www/mysite在旁边的框中输入/home/foo/www/mysite)。

回答by Marius.C

Another thing is to make sure that you disable any firewall you have and which might block remote connections.

另一件事是确保禁用所有可能阻止远程连接的防火墙。