Debugging Magento API Calls with XDebug - php

I have to debug an application (let's call it App A) that communicates with a Magento store through API v1 (via a Zend_XmlRpc_Client).
Here's how XDebug is configured on my php.ini.
xdebug.remote_enable = 1
xdebug.remote_host = 10.0.2.2
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.idekey=PHPSTORM
xdebug.trace_enable_trigger = 1
xdebug.trace_output_dir = "/var/www/xdebug_profile"
xdebug.profiler_enable_trigger = 1
;xdebug.profiler_enable = 1
xdebug.profiler_output_dir = "/var/www/xdebug_profile"
xdebug.remote_log = "/var/www/xdebug_profile/xdebug.log"
When I go to my Magento store through my browser and enable debugging (using Xdebug chrome extension), I can debug my Magento store.
I would like to do the same thing from my App A. I want to access to my App A through my browser and be able to debug the Magento code that is executed through API calls. I tried to pass a cookie to the XML RPC client this way (following this article: http://inchoo.net/magento/magento-xdebug/ ) :
$xmlrpc_client->getHttpClient()->setCookie('XDEBUG_SESSION', 'PHPSTORM');
But it's not working. I also tried XDEBUG_SESSION_START for the cookie name, I tried to pass ?XDEBUG_SESSION_START=PHPSTORM at the end of the URL that my client calls and it's not working either.
FYI, I'm using a vagrant environment, both applications are using the same IP. Here's the content of my /etc/hosts file :
<my_vagrant_ip_address> dev.mysuperstore.com dev-app-a.mysuperstore.com
Any help is highly appreciated !

Just add ?XDEBUG_SESSION_START=filter_string at the end of the url
https://{{url_magento_test}}/rest/default/V1/task_blogext/posts?XDEBUG_SESSION_START=PHPSTORM

All you need to add for get working debug is to add this lines in xdebug.ini and to connect it:
zend_extension=xdebug
[xdebug]
xdebug.mode=debug
xdebug.client_port=9000
xdebug.client_host=host.docker.internal
xdebug.discover_client_host=1
After this, install chrome extension debug helper, and press in it debug mod. And all will work great.

Related

XDebug breakpoints aren't hitting

I am trying to get XDebug (version 2.5.4) working with PHP Storm, with PHP 7.
I am using Windows and running my application off of a CentOS virtual machine, with PHP 7 set up in the CLI settings of PHP Storm, in order to debug.
Here is what my configuration looks like:
[xdebug]
zend_extension="C:\wamp64\bin\php\php7.0.10\ext\php_xdebug.dll"
xdebug.remote_enable = 1
xdebug.remote_connect_back = 1
xdebug.idekey = "PHPSTORM"
xdebug.remote_autostart = 0
xdebug.remote_port=9000
xdebug.remote_host=etc...
xdebug.remote_handler=dbgp
I am using Postman, with ?XDEBUG_SESSION_START=PHPSTORM at the end of the API endpoint, and the cookie with contents XDEBUG_SESSION=PHPSTORM; in the body.
I am clearly setting breakpoints, but I keep getting the message Debug session was finished without being paused
I also have the path mapping set up correctly, between the File/Directory and Absolute path on the server:
I can also get it to stop at the first line by setting the "Break at first line in PHP scripts" checkbox in PHP Storm. I just doesn't stop at my set break points.
Can anyone recommend what I need to do in order to get the break points to hit?

XDebug is pausing just once

I'm using PHPStorm and Xdebug. I'm trying to debug a Web Application Project configured in my localhost. There are no symbolic links in my project path.
Below is Xdebug configuration in my php.ini:
[Xdebug]
xdebug.remote_port=9000
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.profiler_enable=1
xdebug.remote_host=localhost
xdebug.remote_handler=dbgp
xdebug.idekey = "PHPSTORM"
xdebug.profiler_output_dir="/tmp"
xdebug.remote_log="/tmp/xdebug.log"
zend_extension=/usr/local/php5/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so
Below are two variables exported in my zsh:
export PHP_IDE_CONFIG="serverName=localhost"
export XDEBUG_CONFIG="idekey=PHPSTORM"
Below is server configuration:
Below is debug configuration:
Below is the screenshot of first breakpoint where I see no variable values.
Below is the screenshot after 'Step In'. It shows: Waiting for incoming connection with ide key 'PHPSTORM'.
I get below message in event log:
Debug session was finished without being paused.
It may be caused by path mappings misconfiguration or not synchronized local and remote projects.
To figure out the problem check path mappings configuration for 'dev.sales-crm.com' server at PHP|Servers or enable Break at first line in PHP scripts option (from Run menu).
My problem is: after debugging is started, then control stops at first breakpoint. It shows no variables values. Then If I try to 'step into', then debugging stops.
Please help me. Below is the link to xdebug logs: xdebug.log
I upgraded my Xdebug version form Xdebug 2.5.0rc1 to Xdebug v2.5.0 and it started working.
Thank you very much.

Debug Project in PhpStorm

I have been searching for a satisfactory answer on the net and StackOverflow without success. How should I debug Magento as a whole application — not a single file — using the PhpStorm IDE? You can do this in Visual Studio, Netbeans, and IntelliJ IDEA but I need to know how to debug an application, such as Magento, using PhpStorm.
When I try to run the debugger on a controller, such as C:\xampp\htdocs\coinandbuillion\app\code\core\Mage\Checkout\controllers\CartController.php, a bunch of errors get thrown because PhpStorm is trying to execute the file directly rather than working through the application dispatcher in index.php.
So does anyone know how to debug automatically from the initialization point of application till the end?
Here is snapshot what i got. I cant debug after that button click.
Finally I did it !!! :) Please refer steps I followed.
Install Jetbrain's chrome extension from Here.
Now follow steps as below.
In 3rd snapshot in image. your Built in server port(mine is 63342) may be different for you,I didnt change it , it was already there(default), I have just shown it. I changed other options only.
That's it !!
Edit 1:
IF you have problem writing all xdebug setting in php.ini from diagram 1, here it is text version: Don't change paths exactly like i have because you may have xampp/wamp installed on other drive, in different folder. So please add paths like zend_extension accordingly.
[XDebug]
zend_extension = "C:\xampp\php\ext\php_xdebug.dll"
xdebug.profiler_append = 0
;xdebug.profiler_enable = 1
xdebug.profiler_enable_trigger = 0
xdebug.profiler_output_dir = "C:\xampp\tmp"
xdebug.profiler_output_name = "cachegrind.out.%t-%s"
xdebug.remote_enable = 1
xdebug.remote_handler = "dbgp"
xdebug.remote_host = "127.0.0.1"
xdebug.trace_output_dir = "C\xampp\tmp"
xdebug.remote_port = 9000
xdebug.idekey=PHPSTORM
Ensure following :
Ensure you have Installed Chrome Extension from Here
Make sure xampp/wamp server is running.
Make sure Xdebug debugger is configured.
If not , Goto File->Settings -> search PHP and follow diagram as follows

How do you configure xdebug to work with https?

I can't get xdebug to catch on a breakpoint using https, but it works fine with http. Here is the xdebug config in php.ini:
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_autostart = 0
xdebug.remote_connect_back = 0
xdebug.idekey = "netbeans-xdebug"
I've looked over the xdebug docs but can't find any mention of https. Is there any way to make this work?
I had the same issue with PHPStorm/IDEA. Had to change host port from 80 to 443 in Servers settings
Preferences -> Languages & Frameworks -> PHP -> Servers
Xdebug shouldn't behave differently over SSL, so I suspect the problem to be in NetBeans. Can you try another client and see if that works? You can find a list of clients here: http://xdebug.org/docs/remote
Turned out to be an issue with curl passing the request along in the environment. See here for more help with that.

Xdebug with local api using vagrant

I have xdebug working locally for 'normal' sites (I am using google chrome with xdebug helper and phpstorm to talk to a site hosted on a vagrant box).
However if I try and connect to a locally hosted api site (also on a vagrant box) using a REST client (google chrome's advanced rest client plugin) it will not work.
What settings do I need for xdebug on the vagrant box, and what additional information do I need to include when making api calls?
My settings (on the vagrant machine) which work for phpstorm and vagrant box are as follows:
;;;;;;;;;;;;;;;;;;;;;;;;;;
; Added to enable Xdebug ;
;;;;;;;;;;;;;;;;;;;;;;;;;;
zend_extension="/usr/lib/php5/20100525/xdebug.so"
xdebug.default_enable = 1
xdebug.idekey = "vagrant"
xdebug.remote_enable = 1
xdebug.remote_autostart = 0
xdebug.remote_port = 9000
xdebug.remote_handler=dbgp
xdebug.remote_log="/var/log/xdebug/xdebug.log"
xdebug.remote_host=10.0.2.2
the idekey setting connects to a user defined application on phpstorm (see here: http://www.mailbeyond.com/phpstorm-vagrant-install-xdebug-php)
Through much striving managed to fix this with the help of #LazyOne
Here are my final settings if anyone else needs help:
XDEBUG FOR API
; Enable xdebug extension module
zend_extension=xdebug.so
; see http://xdebug.org/docs/all_settings
xdebug.max_nesting_level = 250
xdebug.max_nesting_level = 250
;for ubuntu
zend_extension="/usr/lib/php5/20100525/xdebug.so"
;for centos
;zend_extension="/usr/lib64/php/modules/xdebug.so"
xdebug.default_enable = 1
xdebug.idekey = "PHPSTORM"
xdebug.remote_enable = 1
xdebug.remote_autostart = 0
xdebug.remote_port = 9000
xdebug.remote_handler=dbgp
xdebug.remote_log="/var/log/xdebug/xdebug.log"
xdebug.remote_host=10.0.2.2
• Change symfony2 app_dev.php to:
//$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
$loader = require_once __DIR__.'/../app/autoload.php';
• May also need to put a breakpoint on the app_dev.php and try 'stepping into' the main project. This will prompt you to set up paths on the edit path mappings link: http://blog.jetbrains.com/webide/2011/02/zero-configuration-debugging-with-xdebug-and-phpstorm-2-0/
• On REST client as a header: cookie XDEBUG_SESSION=PHPSTORM
You also need to include:
?XDEBUG_SESSION_START=PHPSTORM (e.g. /courses/?XDEBUG_SESSION_START=PHPSTORM)
as a parameter if using a REST client. PHPSTORM's client will add it automatically

Categories