How to debug a page called from javascript?

I have a problem on a php page I'd like to debug.
I have a break point set, but It doesn't stop there.

My project is fairly simple:
grid.html - the launching point for the project (displays a jqgrid)
server.php - the back end code for updates/inserts/deletes

What I am doing to debug is right clicking on grid.html when it's open in the editor and choosing 'debug'
Firefox opens with the page.
the Debug tab in PHPStorm shows 'Connected'

Is there another step I need?
This is using PHPStorm EAP 100.36 on OSX 10.6.5 running MAMP.

Also, as a side note, if I open server.php in the editor, right click and choose debug, it stops at my first breakpoint so debugging in general works.
Hopefully I am missing something simple to allow the debugger to be invoked during the callbacks from grid.html's javascript code.


0
4 comments

Hi Jack,

I do not know what exactly you are missing, but here is general checklist for external debugging (when debug request comes from navigating to the page in browser):
1) Make sure you have mappings set up correctly -- Settings | PHP | Debug Mappings.
2) Make sure PhpStorm can accept external debug connections (ON by default) -- Settings | PHP | Debug.
3) Set breakpoint(s) or tick "Break at the first line" in Settings | PHP | Debug (ON by default)
4) Turn ON debug listener (that new icon on toolbar -- the one with phone handle)
5) Navigate to your HTML page
6) Using browser extension or sriplet (see the blog post) activate debug session (this will set Xdebug cookie).
7) Now click the link/button/trigger the action which will send request to that PHP script (or just reload the page if the script is used during that period only)
8) Debug

Obviously, the above assumes that HTML page and PHP script are on the same domain (as debugging cookie is set for exact domain).

0
Avatar
Permanently deleted user

Thanks Andriy,

   It sounds like nothing special is needed outside of the normal config.

   I'll double check my settings.

   Something interesting did happen while I was messing around with this yesterday.

   Clicking debug stars the debug session in Firefox on my starting HTML page.

   Navigating from there doesn't invoke the debugger's break points, even on PHP pages.

   However, I also happened to have a safari window open, and when I navigated that to the pages, The debugger kicked in.

   I'll do some more investigating and double check my settings.

- Jack

0

Hi Jack,

When you starting debugger from PhpStorm (by clicking debug button), PhpStorm will open the URL in browser with additional special URL param (XDEBUG_SESSION_START=idekeyhere).

When you launching PHP script in this way, the Xdebug will see such parameter, will set the debug cookie and will start debugging session. But when you launching HTML or any other file that is not processed by PHP, Xdebug is not get involved and no session cookie is created (unless such cookie still present from previous debug session or already set by some browser extension or scriptlet).

P.S.
Of course you can set your webserver config up in such way that PHP will process files with ANY extension (.html, .css, .js, .png etc), not just .php -- but I do not think it is your case here.

Please also note, that Xdebug under some circumstances can completely ignore some valid breakpoints -- see ticket WI-2191.

0
Avatar
Permanently deleted user

Andriy,

Thanks!:)

0

Please sign in to leave a comment.