簡體   English   中英

Xdebug忽略了Netbeans中為Docker容器內創建的Php項目的斷點

[英]Xdebug ignores breakpoints in Netbeans for Php project created inside Docker container

當我調試未在Docker容器中創建的項目時,Xdebug沒有問題。

但是當我調試在Docker容器中創建的項目時,Xdebug不會在斷點上停止 - 盡管它正在運行並且在xdebug_break()上停止。

我的Docker主機是Ubuntu 14.04。 它安裝為VirtualBox。 它使用PHP 5.5.9-1ubuntu4.16和Xdebug v2.2.3。 我有一個已安裝的卷(在Docker主機和Docker容器之間),其中存儲了在Docker容器中創建的項目。

Ubuntu 14.0.4中的我的Docker容器基於CentOS版本6.7(最終版)。 它使用PHP 5.3.29和Xdebug v2.1.4,它的Xdebug配置如下(在/etc/php.d/xdebug.ini中):

zend_extension=/usr/lib64/php/modules/xdebug.so
;xdebug.remote_autostart = 0
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 1
xdebug.remote_enable = 1
;xdebug.remote_host = 127.0.0.1
;xdebug.remote_host = localhost
;xdebug.remote_host = 172.17.42.1
;xdebug.remote_host = 10.0.2.15
;xdebug.remote_host = 10.0.2.2
;xdebug.remote_port = 9001
xdebug.remote_port = 9000
xdebug.remote_handler = dbgp
xdebug.profiler_enable_trigger = 1
xdebug.profiler_output_dir = /home/devteam/xdebug/profiler
xdebug.remote_log=/home/devteam/xdebug/xdebug.log
xdebug.profiler_output_name = cachegrind.out.%c
xdebug.show_exception_trace = 1
xdebug.idekey = netbeans-xdebug

我已經檢查了xdebug.remote_port設置的所有值,當前顯示為已注釋掉的值。 我為xdebug.remote_port設置嘗試了不同的端口(9001,9002)(當然在Netbeans中設置了相同的端口)。 我還嘗試更改xdebug.remote_connect_back和xdebug.remote_autostart設置。 我注意到,這兩個設置為零,xdebug實際上是掛起並等待連接。

但是,在調試先前部署在Docker容器中的項目時,我仍然無法使Xdebug在斷點處停止。

我不確定是否遺漏了有關Netbeans設置或Xdebug設置的任何內容。 我花了很多時間試圖找到解決方案。 我試圖在xdebug.log中找到一些相關信息 - 但它似乎沒有包含任何對我有意義的信息:

...
<- breakpoint_set -i 1567 -t line -s enabled -f file:///var/www/html/test/index.php -n 3
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="1567" state="enabled" id="11710015"></response>

<- breakpoint_set -i 1568 -t line -s enabled -f file:///home/pkowalski/clients/deployments/demon-prep/application/bootstrap_http.php -n 7
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="1568" state="enabled" id="11710016"></response>

<- run -i 1569
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="run" transaction_id="1569" status="stopping" reason="ok"></response>

Log closed at 2016-05-20 23:38:11

Log opened at 2016-05-20 23:40:23
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///mnt/deployments/demon-prep/application/bootstrap_http.php" language="PHP" protocol_version="1.0" appid="1172" idekey="netbeans-xdebug"><engine version="2.1.4"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2012 by Derick Rethans]]></copyright></init>

<- feature_set -i 1570 -n show_hidden -v 1
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="1570" feature="show_hidden" success="1"></response>
...

它似乎成功地設置了斷點,但我不確定xdebug.log中的文件路徑是否正確。 也許我需要在Netbeans中使用手動路徑映射,但我不知道該怎么做以及什么路徑應該是服務器路徑。

現在,如果我開始調試,頁面加載。 但是之前的一段時間,瀏覽器內部出現錯誤,說連接已重置。 除此之外,還出現了幾次錯誤彈出窗口。 有時候一個彈出窗口說Netbeans和Xdebug之間存在通信問題。 其他時間顯示不同的消息 - 存在套接字連接錯誤。 我不知道為什么現在我沒有看到這些彈出窗口。

知道什么可能是Xdebug的解決方案忽略Netbeans中的斷點在Docker容器內創建的項目?

最后我自己解決了這個問題。

正如我所料,解決方案是在Netbeans中正確設置路徑映射

今天再次分析xdebug.log后,我注意到日志的開頭包含有趣的信息 - init元素的屬性fileuri的值:

<init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///mnt/deployments/my-project/application/bootstrap_http.php" language="PHP" protocol_version="1.0" appid="139" idekey="netbeans-xdebug"><engine version="2.1.4"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2012 by Derick Rethans]]></copyright></init>

在我的Docker容器的run docker子命令期間,我使用Docker容器共享包含my-project的 Docker主機目錄的方式是: docker run ... -v / home / pkowalski / clients / deployments:/ mnt / deployment

所以我用Netbeans忽略了my-project的斷點來解決這個問題,我只是在Netbeans中設置Path Mapping(Project Properties - > Run Configurtion - > Advanced),如下所示:

服務器路徑:/ mnt / deployments / my-project

項目路徑:/ home / pkowalski / clients / deployments / my-project

因為我在Docker容器中為掛載目錄創建了一個軟鏈接: ln -s / mnt / deployments / home / devteam / deployments ,最初我嘗試將/ home / devteam / deployments / my-project作為Server Path值,但它沒有用。

除此之外,現在工作對我來說,沒有xdebug.remote_host設置都與xdebug.remote_autostart要么設置為0或1。

這是我的/etc/php.d/xdebug.ini在Docker容器中的最終工作內容:

zend_extension=/usr/lib64/php/modules/xdebug.so 
xdebug.remote_autostart = 0
xdebug.remote_connect_back = 1
xdebug.remote_enable = 1
xdebug.remote_port = 9000
xdebug.remote_handler = dbgp

我的朋友,我的機器遇到了類似的問題。 我的機器已經安裝了常規設備,並且安裝了docker模塊。 所以我所做的就是啟動php-xdebug包,它為我解決了。

命令: sudo apt purge php-xdebug

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM