Debugging within the CakePHP Console

Sep 22 2011

Recently I've been doing some development of classes that run under the Job Queue CakePHP plugin, a great plug in btw, and I had a need to debug some of the logic.  As a reminder I use NetBeans 6.9.x on XPsp3 to develop code that is housed on a CentOS 5.6 VirtualBox instance that I access via a Samba share. 

Debugging the Cake console is pretty straight forward, so I thought I'd take a second and do a quick writeup on how to set things up.  

First, the official Xdebug docs on how to do this are here under the section "Starting The Debugger"

So here is how I did this.  Add this statement to your environment, this is for the command line and will stay active until you log out: 

export XDEBUG_CONFIG="idekey=netbeans-xdebug" 

You can add an export in your bash_profile to make this a permanent setting as well. 

Note that the idekey value above needs to match the idekey value you have setup in NetBeans.  You can check you current NetBeans setup in v6.9 by clicking Tools/Options and then clicking the PHP icon in the icon bar.  Within NetBeans "idekey" value is shown as the "Session ID", just make sure the the idekey value in the export statement matches the Session ID in NetBeans.  While you are on this screen you'll want to uncheck the "Stop at first line" option.  

Now load the file containing the console program that you want to debug in NetBeans, and set the breakpoint on the line where you want to break.  Turn on the NetBeans debugger (it should be sitting in a wait mode now), pop over to your SSH session and make the cake/console folder your current folder, then execute your console command. 

In my case the launching the runworker in the Job Queue would look like:

./cake queue runworker 

When the logic hits the breakpoint my NetBeans session becomes active and I debug away.  If you want to remove the environment variable XDEBUG_CONFIG you can use

unset XDEBUG_CONFIG

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.