I'm trying to debug PHP code executed by a RabbitMQ consumer.
xdebug is working fine in both CLI and http, but it fails when something is executed from a queue. I have set the following trace:
ini_get("xdebug.idekey")
ini_get("xdebug.remote_host")
ini_get("xdebug.remote_connect_back")
ini_get("xdebug.remote_mode").
ini_get("xdebug.remote_autostart")
php_ini_loaded_file()
getenv("XDEBUG_CONFIG")
It prints:
""
localhost
1
req
0
/etc/php5/cli/php.ini
xdebug.idekey=sublime.xdebug
xdebug.remote_host=10.5.223.108
xdebug.remote_connect_back=0
xdebug.remote_mode=req xdebug.remote_autostart=1
So the problem seems to be that it is ignoring the environment variable XDEBUG_CONFIG and is using the values in the cli ini file. I don't have permissions to modify the ini file, and the XDEBUG_CONFIG variable works fine when executing something via CLI.
Any ideas why XDEBUG_CONFIG is being ignored when the code is executed from a queue?
Xdebug and RabbitMQ consumer commands
To make your IDE aware of the connection you need to prefix the command with the environment variable:
XDEBUG_CONFIG="put-here-your-value" php my-script.php
Related
I have configured PhpStorm to connect to a remote web server. I am running phpunit for unit tests. I have xdebug running and have created an ssh tunnel for debugging. I know xdebug is running as I am able to click and run a phpunit test (with breakpoint set) by just clicking the run button (after turning on listening for PHP debug connections). However if I instead choose the Debug option in PhpStorm I get connection errors.
Enabling debug messages to the PhpStorm log file I see that the command being sent is:
DEBUG - ellij.ssh.SshConnectionService - Executing SSH command:
cd /[path to project files];
exec env "IDE_PHPUNIT_CUSTOM_LOADER"="/[path to autoloader]/autoload.php" "JETBRAINS_REMOTE_RUN"="1" "XDEBUG_CONFIG"="idekey=17650" /usr/bin/php -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9002 -dxdebug.remote_host=[ip address] /[path to phpunit]/phpunit/phpunit --configuration /[path to phpunit xml file]/phpunit.xml --filter '/(::myTestClassMethod)( .*)?$/' 'another method being tested' /[path to unit test file]/myUnitTest.php --teamcity within SshjSshConnection([blah]#[foo])#bar
My php.ini settings are expecting idekey=PHPSTORM but I'm seeing a numeric key in the command line that keeps changing for each attempt.
I'm assuming these two values for idekey need to match. If that's correct how do I do that?
Thanks
They don't need to match. In fact, PhpStorm is just overriding it here so that it can match against what it expects.
I don't understand why it does that, as IDE Keys are (currently) only used in combination with DBGp proxies.
As you don't describe what "connection errors" are, it's not really possible to provide an answer to that part of the question yet.
I am trying to use the Oracle connectivity by oci_connect function with JBoss (where Server API is CGI/FastCGI), I am unable to show environment variable over phpinfo() function with JBoss(where Server API is CGI/FastCGI), which is already working fine with PHP and Apache.
Below are the parameters which are showing by jboss/(CGI/FastCGI), system environment variable PATH(which is needed to enable the oci8 module of php) and some other parameters are missing with JBoss.
CGI/FastCGI Environment
Variable Value
PHP_FCGI_CHILDREN 5
PHP_FCGI_MAX_REQUESTS 10000
REDIRECT_STATUS 200
SystemRoot C:\WINDOWS
__COMPAT_LAYER ElevateCreateProcess
Apache Environment
HTTP_COOKIE csrftoken=5LL6M3KDqW6zbW947SUd5qKiDNYvkDiKtNTKO8kbAhiECWitdjdncL2ZRnQQyYVl; PHPSESSID=s2fcp7cbjijjc77i5g195koiil
PATH C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\RSA SecurID Token Common........;
Can anyone provide the help/steps to display the environment variable with JBoss and CGI/FastCGI?
FYI: I am using the window 10 environment.
As I verified the my Project.war file, which has been bundled the php-cgi.exe with php 5.6, here we had the wrong version of java.inc file which Compile The PHP/Java Bridge for PHP library.
I changed my java.inc file then the issue have resolved, and now I can see the oci_connect module inside the phpinfo()
So I realized that, I would have need to use correct java bridge file.
OCI8 Module
=========================================================
Ignore this post. A much simpler statement of this issue can be found at PHP auto_prepend_file causes xdebug profiler to fail
=========================================================
Original Post (and updates)
When I try to open an xdebug profiler snapshot within PhpStorm using:
menu bar >> Tools >> Analyze xdebug profiler snapshot...
I select the file xDebug created but I'm faced with this error:
Error: Incorrect profiler snapshot format: Incorrect name format
I did not rename the snapshot. It is the default name: cachegrind.out.8008
php.ini
<!-- language:lang-none -->
[xdebug]
zend_extension="php_xdebug-2.5.5-5.6-vc11.dll"
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_autostart=1
xdebug.profiler_enable=1
xdebug.profiler_output_dir="C:\websites\xdebug"
; xdebug.profiler_output_name= ; Commented out to allow default name
xdebug.idekey=PHPSTORM
Why won't PhpStorm open the snapshot? Should I set a custom xdebug.profiler_output_name option?
Update
I closed all my projects, upgraded from PhpStorm 2017.1.4 to 2017.2, restarted Apache, deleted the old snapshots and created a new one. The new one opens without trouble.
Update 2
Seems that if I run a file from the command line by calling >php script.php, the generated snapshot can be opened. If I run the same file from the browser (meaning I go through the Apache webserver: localhost/script.php) the snapshot cannot be opened.
Update 3
I also notice that when I execute from the browser, I can't delete the snapshot until I force-stop the Apache process. The PHP file I'm profiling has no instructions: just <?php. Below are the two snapshots created:
When executed from the command line (PhpStorm opens this file without problem):
version: 1
creator: xdebug 2.5.5 (PHP 5.6.1-dev)
cmd: C:\path\to\script.php
part: 1
positions: line
events: Time
fl=(1) C:\path\to\script.php
fn=(1) {main}
summary: 0
1 0
When executed from the browser (PhpStorm cannot open this snapshot):
version: 1
creator: xdebug 2.5.5 (PHP 5.6.1-dev)
cmd: C:\path\to\script.php
part: 1
positions: line
events: Time
fl=(2) C:\path\to\script.php
fn=(1)
summary: 0
1 0
Update 4
The culprit is the auto_prepend_file ini setting. I had the following set in Apache Vhosts:
php_value auto_prepend_file "C:\path\to\init.php"
This file is run before Apache executes the script that was called from the browser. When I run the script from the command line, this setting (which is in my Apache Vhosts config) never takes effect so init.php doesn't run. Conversely, if I move the setting to php.ini where it also affects command-line execution, then snapshots generated from the command-line also stop working.
If I remove the auto_prepend_file setting, the generated profiler snapshot can be open without problem in PhpStorm. Of course this isn't a fix since I need the auto_prepend_file to execute for my application to work properly.
I'm trying to debug my Drupal 8 tests with XDebug, but if I run them with XDebug switched on, I cannot step into the test. I execute the following command:
vendor/bin/phpunit -c core
modules/permissions_by_term/tests/src/Kernel/SelectTermTest.php
PHPUnit reports me here:
"Can't find a source position. Server name 'localhost' doesn't exist."
My settings in the PHP.ini file are looking as follows:
xdebug.remote_enable=true xdebug.profiler_enable=0
xdebug.idekey=PHPSTORM xdebug.max_nesting_level=256
xdebug.remote_autostart=true
Can anybody share here some experience?
I got it to run. I had to do some more settings.
First, create a new PHP Remote Debug under the Run Configurations (The ZeroConfiguration didn't work for me). Define a Server with the name you want (here "TestServer") and enter PHPSTORM as Ide Key.
Also see the Jetbrains documentation: https://confluence.jetbrains.com/display/PhpStorm/Debugging+PHP+Web+Applications+with+Run+Debug+Configurations
Enable the option "Break at first line in PHP scripts" in under the RUN menu .
It can be possible that you need to override the file mapping. (In my case PHPStorm is not able to detect file mapping automatically) (See: https://www.jetbrains.com/help/phpstorm/10.0/override-server-path-mappings-dialog.html). It's is within same dialog where the server was created.
Start the Remote Debug Session with clicking on the corresponding icon.
Then you should be able to run PHPUnit with this command:
PHP_IDE_CONFIG="serverName=TestServer" XDEBUG_CONFIG="idekey=PHPSTORM" vendor/phpunit/phpunit/phpunit -c YOUPHPUNITXMLCONFIG
Set the PHP_IDE_CONFIG corresponding to your settings.
Set breakpoints where you want to stop.
I hope I could help you.
Nico
I'm trying to debug my PHP script using xdebug and xdebug_break() method. It start to working and my IDE (PHPDesigner) stop at the break normally, but instantly it stop. Reading the debug.remote_logs file I can check that the last line is:
<- context_get -i 429 -c 0
After that I don't receive a return with a XML data about GET data. So I guess that there live the problem, but how can I fix that?
My php.ini xdebug config is:
[xdebug]
xdebug.remote_mode=jit
xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_log=C:\Wamp\logs\xdebug.log
xdebug.idekey=xdebug
I tried to use the XDBG too, and it throw an exception and stop to working. The remote_logs file show the same fail. Using php_xdebug-2.2.0-5.4-vc9.dll.
Before I do post it, I checked out the xDebug last version and it is php_xdebug-2.2.2-5.4-vc9.dll (diff: old 2.2.0, new 2.2.2). Updating that solve my problem and now all works fine. Yey!