Debugging how to switch from JS to PHP debugging and many newb questions

I am trying to build a "final" beta on something I have been working on for three years. I am a jack of all and master of none so please fogie the dumb questions.

I got debugging "working" for the first time today. Xdebug installed properly etc. But...

If I come to a PHP file and want to LiveEdit then I have to do a JS debug and if I want to debug it I have to do a PHP debug. When I click on Debug for the first time in a file I am offered the choice of JS or PHP (in passing those icons are totally unclear - took me months to realize the difference). If I do a live edit all I get in the Debug window is a message: "Connected to JetBrains Chrome Extension".

How do I switch? At the moment all can see is to go to Edit Configuration and delete the current debug and thus get the option of chosing JS or PHP. That cannot be the way to do it can it?

I also have a second problem:

I struggle with paths and urls but have got everything working fine autoloading classes etc but now when I try and debug a simple page I get lots of file not founds.

C:\xampp\php\php.exe -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000
-dxdebug.remote_host=127.0.0.1 C:\xampp\htdocs\sane30\custom\classes\Client.php Warning: include_once(/custom/includes/autoloader.inc.php): failed to open stream:
No such file or directory in C:\xampp\htdocs\sane30\custom\classes\Client.php on line 4

Call Stack:     0.0740     125512   1. {main}() C:\xampp\htdocs\sane30\custom\classes\Client.php:0 Warning: include_once(): Failed opening '/custom/includes/autoloader.inc.php' for inclusion
(include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\sane30\custom\classes\Client.php on line 4



Is there somewhere I should be declaring a root? I noticed the "include_path... \PEAR" which makes me suspicious.


Finally a truly newb question. If I have a form - say form.php - that calls a process page - say process.php - how do I debug process.php by using form.php..... Or am I expecting the impossible.

Thanks in advance for any help that can be offered.

(How do I post code so it looks like code - sorry this is a bit unreadable) Message was edited by: steven homer

3 comments
Comment actions Permalink

Hi there,

Please have a read these official manuals: https://confluence.jetbrains.com/display/PhpStorm/Debugging+with+PhpStorm (it also has videos)

How do I switch? At the moment all can see is to go to Edit Configuration and delete the current debug and thus get the option of chosing JS or PHP. That cannot be the way to do it can it?

You do not need to delete anything.

If you need another debug -- just choose another Run/Debug Configuration in that drop-down box and use Debug button.

Also - have a look at this tutorial: https://confluence.jetbrains.com/display/PhpStorm/Debugging+PHP+and+JavaScript+code+at+the+same+time+in+PhpStorm

C:\xampp\php\php.exe -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=127.0.0.1 C:\xampp\htdocs\sane30\custom\classes\Client.php
Warning: include_once(/custom/includes/autoloader.inc.php): failed to open stream: No such file or directory in C:\xampp\htdocs\sane30\custom\classes\Client.php on line 4
Call Stack:     0.0740     125512   1. {main}() C:\xampp\htdocs\sane30\custom\classes\Client.php:0 Warning: include_once(): Failed opening '/custom/includes/autoloader.inc.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\sane30\custom\classes\Client.php on line 4


This tells that you are debugging PHP script in CLI environment (console) and not in the browser. You need to use "Web Application" type of Run/Debug Configuration or even Zero-Config approach . Via context menu you would have only JS Debug & PHP CLI debug ("PHP Script" type of Run/Debug Configuration)

Is there somewhere I should be declaring a root?

For your own good -- try using absolute paths, something like include __DIR__ . '/path/to/my/file'; (really depends on your code) or paths relative to the current file (e.g. include __DIR__ . '/../../another/file.php';)

Finally a truly newb question. If I have a form - say form.php - that calls a process page - say process.php - how do I debug process.php by using form.php..... Or am I expecting the impossible.

So .. you have a web page form.php that, after you click on "send/whatever" button calls the "process.php" page? If so -- see below.

You would usually use approach described in Zero-Config approach manual -- activate "phone handle" icon to make PhpStorm listening for incoming PHP debug requests; set xdebug cookie in a browser (via Bookmarklets or any xdebug browser extension) and hit the "send/submit/whatever" button on your "form.php" page -- the next request (that will be sent to process.php) will be debugged.

How do I post code so it looks like code

Current PhpStorm versions automatically place code into clipboard that can be pasted here already formatted 8(using your current color scheme by default).

Other option -- just use "Quote" button here on pasted code and apply some monospaced font -- that's enough to read it.

0
Comment actions Permalink

Andriy thank you very much for that wonderfully full answer (I owe you several beers). Trust me I have read lots and lots of official help pages and will start again.

Will probably not do this for a day or two but it will be crucial so a milion thanks.

Steve

PS I always wondered what the phone was for and now I know!!

0
Comment actions Permalink

EDIT: Sorted JS has to be in external file. Bit of a pain as for dev I like to have everything in one file then move it out but ... 

 

Andriy slowly getting there (started yesterday in earnest and this will be fantastically useful).

Dmitry slowly getting there but have hit a problem - I cannot set JS breakpoints. I am using jQuery - does PhpStorm support that - cannot believe it does not. (This is in a PHP file just read you cannot set JS breakpoints in PHP file - that makes no sense if we can use both JS and PHP debugging - I am very confused.) 

 

$(document).ready(function () {
$("[type='checkbox']").on('change', function () {
if ($(this).prop('checked')) {
$(this).prev()
.removeClass('glyphicon-unchecked')
.addClass('glyphicon-check');
}
else {
$(this).prev()
.removeClass('glyphicon-check')
.addClass('glyphicon-unchecked');
}
});

$("input:checked").prev()
.removeClass('glyphicon-unchecked')
.addClass('glyphicon-check')
.parent()
.addClass('active');
Cannot put breakpoint next to any of those.


(I apologize I have cross-posted this with Dmitr's post as want to get on and not sure if either of you are around now (Friday evening in Europe))

ATB
Steve

 

0

Please sign in to leave a comment.