0

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)

timhc22
  • 7,213
  • 8
  • 48
  • 66
  • And .. how do you debug "normal" sites? Please describe (in short). So far (as I understand) xdebug is missing debug marker (cookie or GET/POST parameter that tells xdebug to debug this request). In browser this cookie is added/removed by special browser extension or bookmarklet .. or GET parameter is added to URL when initiated from IDE. For API calls you will need to add such info yourself .. or configure xdebug to debug every single request. – LazyOne May 15 '14 at 22:21
  • For 'normal' sites I: use the settings outlined above on the vagrant machine; use google chrome's xdebug helper which send the required session start information, and configure phpstorm as outlined here http://www.mailbeyond.com/phpstorm-vagrant-install-xdebug-php by creating a 'server' and attaching it to the debug configuration (this is how xdebug.idekey = 'vagrant' talks to phpstorm) – timhc22 May 16 '14 at 13:16
  • I cant seem to get it working with REST client even if i include the debug marker as outlined here: http://stackoverflow.com/questions/19139803/xdebug-a-restful-server-using-phpstorm-or-postman – timhc22 May 16 '14 at 13:18
  • `xdebug.remote_autostart = 1` in your php.ini is the safest way to go (every single request will be attempted to debug). Make sure that correct php.ini is edited (in case if you have more than one -- the case on some Linux distros/Mac) – LazyOne May 16 '14 at 13:24
  • 1
    You can ignore "Add Remote Server" step -- IDE will help set it up on first incoming connection. Right now it's possible that your path mappings are incorrect. – LazyOne May 16 '14 at 13:25
  • In any case: please collect extra logs: PhpStorm side: http://devnet.jetbrains.com/docs/DOC-1202 ; xdebug side: http://xdebug.org/docs/all_settings#remote_log – LazyOne May 16 '14 at 13:26
  • I see in the xdebug logs that it is saying this: Log opened at 2014-05-16 13:47:16 I: Connecting to configured address/port: 10.0.2.2:9000. E: Time-out connecting to client. :-( Log closed at 2014-05-16 13:47:16 – timhc22 May 16 '14 at 13:48
  • it must be the path mappings then surely, but I'm confused because they are exactly the same as the settings in my vagrant box for 'normal' sites and it works fine in there..? – timhc22 May 16 '14 at 13:52
  • it seems to be connecting now but getting different errors! – timhc22 May 16 '14 at 13:57
  • -> <![CDATA[L2NvdXJzZXM=]]> – timhc22 May 16 '14 at 13:58
  • So it's solved? Good. – LazyOne May 16 '14 at 14:03
  • I put a break point on the front controller of my symfony2 application and it works there, but stepping through says the 'remote file /path/bootstrap.php.cache' is not mapped to any file path in project. I can probably work out what is going on from here – timhc22 May 16 '14 at 14:11
  • 1
    From what I see that file has `.cache` extension. If possible -- copy it to local project files (do not forget to associate `.php.cache` with PHP files otherwise IDE will not treat it as PHP file and will not be able to step it trough). Plus, you may need to copy it over again after each modification of important/participating files. Alternatively (the best) -- try disabling such caching. – LazyOne May 16 '14 at 14:18
  • ah yes amazing, didn't realise symfony2's caching would affect it. Fixed it by following this here: http://stackoverflow.com/questions/16635463/debug-symfony2-projects-in-phpstorm thank you SO much,I can't tell you how grateful I am – timhc22 May 16 '14 at 14:34

1 Answers1

2

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

enter image description here

timhc22
  • 7,213
  • 8
  • 48
  • 66