Showing posts with label one year post. Show all posts
Showing posts with label one year post. Show all posts

Monday, January 05, 2009

Easy Remote PHP Debugging with VIM and Firefox

Happy new year !

I've write a post bout how you can setup debugging environment for PHP using xdebug, so now assuming you have xdebug setup and loaded, I'm going to write bout how you actually debug your PHP code.

Basically there are 2 type of debugging, local or remote debugging, the difference is that whether or not the debug engine separated with the debug client. If you debug a desktop Java code using IDE like Eclipse, most likely you are doing local debugging, where as the debug engine comunicate directly to the eclipse interface (there is no need of debug client). XDebug is a remote debug engine, which mean to actually debug some code we need a debug client to send command to and receive debugging information from the debug engine. From XDebug page we can get alot information bout how this can work, and some option of debug client that you can use (this page should be your first reference).

Now lets get to the chase, I'll write about how to have a remote debugging session with Vim (with plugin) and firefox to debug your PHP code easily.
  1. After you have successfully load xDebug module into php, enable remote debugging in your php configuration (php.ini) by adding
    xdebug.remote_enable = "1"
  2. download the debugger plugin (or watch my blog for an update)
  3. extract the file (debugger.vim and debugger.py) to your home vim plugin directory
    $ unzip debugger.zip
    $ cp plugin/debugger.* ~/.vim/plugin/
  4. fire up Vim!, make sure your build equiped with signs and python support or the plugin won't work!, I'm using ubuntu and a Vim-full package for this, no hush, no mush..
  5. if vim loaded without any error it means the plugin already loaded correctly, if not check your vim build, make sure the +signs and +python is there when you type in vim command
    :version
  6. open firefox, and install this addon
  7. open the PHP application you wish to debug using firefox, make sure the source code is accessible. for example if the source is in (assume you are using xampp)
    /opt/lampp/htdocs/testdebug/index.php
    then you can type in firefox url
    http://localhost/testdebug/index.php
  8. click the xdebug helper icon (the one you've just add) on firefox status bar (default on lower right corner), now the icon should flash green
  9. switch to your vim window and press F5 (the message window would say waiting for connection...)
  10. switch to your firefox window and reload by pressing F5,
  11. now switch to your vim window (again) and there you have it, a debugging interface of your application in vim.
let me explain a few of those steps a little bit (step 1 to 7 should be clear enough), step 8 means you have start a debugging session for the next http request, it is the same as if you append the url with XDEBUG_SESSION_START=1 so the url would be
http://localhost/testdebug/index.php?XDEBUG_SESSION_START=1
ofcourse clickin on xdebug helper icon is alot more convenience than appending the url each time we start a debugging session.

now for step 9 we prepare our beloved Vim to wait a connection from the debug engine at this point vim will kind of hang (waiting mode), the script default timeout is 5 second, if within that there are no debugging session requested, vim will return to normal mode. This means than we have to quckly run step 10, switch to firefox and reload, but again make sure the xdebug helper icon is already flash green (activated/clicked). After you have reload the page if you notice the loading status of the page is keep on spinning, the page wont finish loading until the debugging session stopped or vim is closed or request timeout

Now if we switch back to Vim, our debugging interface should up and running there are source, watch, help, stack and trace window. From this interface you can trace the code using F2 (step into), F3 (step over), F4 (step out). To end a session you can press F6. One of most common task is to put a breakpoint in our code, to do that open the file you wish to debug, position your cursor on a line you wish to stop and type :Bp in vim command window, now everytime the debugging session start, just press F5 to run until execution point reach the breakpoint. You can see other debugging command from the help window.

one thing about this vim plugin, there aren't that much debugging command available, either from the plugin or xdebug itself, from what I can tell it is more than enough to do my daily-debugging-basis. There are some lacks though, but I'll address this issue later on, considering this post is already bloated enough to make people sick from reading it :p

happy vimming (and debugging) !

keyword: ubuntu, vim, firefox, xdebug, php

Saturday, February 23, 2008

What's this? a one year one post blog ?

heeeeeeeehhh???....
beneran, bener2 setaon gw br megang blog ini lg... bisa jadi rekor ney ^^...

so ? why am i visiting my old, no good, useless, crampy, inapropriate ?, .. ehh (how do u say 'g penting banget' in english with the correct tone ?) blog again ?

its because, i've just read my friends blog, and this strange feeling creeping in, it's almost like hearing them from inside...

crap!!, what am i talking about.... ??

ok, lets just see what and how many will show this year...

zzzzzzzzz....

Wednesday, February 21, 2007

a year ??

d**n its almost a year,...

baru sekarang gw nyentuh nih blog,..
im tryin to write more, wish me luck :p

Saturday, April 01, 2006

cant figure everything out.....

From last night i've been wasting my time to study, since today i have my quiz on DAA subject, which fortunately a "take-home" quiz

Noooo, actually i've been playing with my friends at laboratory all night long :p

Almost forgot what i want to write, its been almost a week since we have upgraded bandwith in our campus, delightfull!!
that's one of the reason why i would bother writing my own blog, because i'm not accustom with the speed yet, so there's time when i dont know what else i want to do in the internet :).