Debug PHP command line with Xdebug and Netbeans

While running FuelPHP tasks on the command line I get some trouble with debugging.
It's simple to have Xdebug running with the server but not so obvious to get it running with the command line.
I've finally found out how !

Now, I'll show you how to setup php command line debug with Netbeans on Windows.
I'm currently using XAMPP and my webroot folder is C:/www/fuel.dev

Xdebug install check

In your command line do a "php -v" an your must see something like this :

php -v  
PHP 5.3.5 (cli) (built: Jan  6 2011 17:54:09)  
Copyright (c) 1997-2010 The PHP Group  
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies  
    with Xdebug v2.1.0rc1, Copyright (c) 2002-2010, by Derick Rethans  

If you see the last line, this indicates that Xdebug is running.

Xdebug configuration

If you're already debugging with Xdebug, your setup is nearly good.
Open your php.ini file. Xampp uses only one php.ini for cgi and cli. You can find it in yourXamppFolder/php/php.ini.

Check that your base setup for debugging is :

xdebug.remote_enable = On  
xdebug.remote_handler= dbgp  
xdebug.remote_mode   = req  
xdebug.remote_host   = 127.0.0.1  
xdebug.remote_port   = 9000  

If your setup is different than this one and your debugging is working, it's ok.
The only important point is to change the xdebug.idekey to have :

xdebug.idekey = "netbeans-xdebug"  

Where the idekey reflect the one entered in the Netbeans setup. We'll see that bellow.
Then save your php.ini and restart your server.

Netbeans setup

General setup

Go to Tools > Options > PHP > General Tab :

  • Fill the PHP 5 interpreter by browsing,
  • Optionally check "Output Window" if you want to see command line output,
  • Optionally uncheck "Web Browser" if you don't want to see command line output in a browser,
  • Check that "Debug Port" is the same as the xdebug.remote_port value,
  • Check that "Session ID" is the same as the xdebug.idekey value,
  • Click OK.

General setup for Netbeans PHP command line debugging

Project setup

Right click on your project in the Project panel and go to Properties > Run Configuration

In this panel you already have your configuration for server debuging.

  • In the configuration line : hit "New",
  • Name it PHP CLI or Toto,
  • "Run As" : Script,
  • The "PHP interpreter" can be the default one we've already setup,
  • Select the script you will run in command line (change this any time you want to run another script, because debug session is ending with the script),
  • "Arguments" and "Working Directory" are up to you depending on the command you need
  • "PHP Options" : -d xdebug.idekey=netbeans-xdebug
  • Click OK

Project setup for Netbeans PHP command line debugging

Let's debug the command line

You can now it your Debug button and you're ready to develop new tasks for Symfony, FuelPHP or any good code you like to use.

Happy coding !

Dojo javascript  toolkit -  -

My Dojo cheat sheet

Dojo javascript framework is really usefull. As I use it in my SVG R&D effort, here's my personal cheat sheet.
Work in progress.

An orchyd from France - by David Jacquel - copyleft

Sending email when dmContactPlugin form is filled on site

dmContactPlugin plugin allows visitors to send you messages. We'll listen to this event to append and send a mail to the webmaster.

 -  -

limiting dmMedia upload size in Diem

In Diem, dmMedia is a nice tool that helps a lot to get a good media management in a web site. However, I've noted that users are not so comfortable with naming conventions or image size constraints.
I've decided to hack the dmMedia plugin to help users conform with pictures management.

 -  -

Insert beautiful code in your Diem posts with Mardown and Geshi

It's nice to present code in our posts, it's better with indentation and syntax highlight. This is possible in Diem with the use of Markdown and Geshi library.

 -  -

Using less css preprocessor with Diem

Using a Cascading Style Sheet Pre-Processor (CSSPP) like LESS or SASS can greatly reduce css development and maintenance time.
Now you can easily use LESS with Diem. Some explanations.