Debugging Magento Xdebug

Published on June 2016 | Categories: Documents | Downloads: 27 | Comments: 0 | Views: 234
of 2
Download PDF   Embed   Report

Comments

Content

Search

 

Debugging Magento with Xdebug

Diagnostic p r i n t _ r  statements and logging might be quick and easy tools for investigating what Magento is doing, but a full debugger offers a lot more power and flexibility. This post demonstrates how to set up the xdebug debugger for use with the vim editor. First of all, I'd like to thank Box.net for their great Xdebug tutorial (http://tech.blog.box.net/2007/06/20/how­to­debug­php­with­vim­and­

xdebug­on­linux/). Check it out for a more in­depth look at using Xdebug and vim.
1.  To start, install the Xdebug PHP extension on your server. Note that this has to be installed as a Zend extension, not a normal PHP extension. You can obtain the Xdebug extension from xdebug.org (http://www.xdebug.org), or you can install it via your package manager on a Linux system. On a Debian­based system, use: a p t ­ g e t   i n s t a l l   p h p 5 ­ x d e b u g Edit your PHP config file and make sure you have the following settings. The z e n d _ e x t e n s i o n  line may point to a different location for your system. (If you have installed Xdebug using a package manager they may already be set up for you.) z e n d _ e x t e n s i o n=/ u s r / l i b / p h p 5 / 2 0 0 6 0 6 1 3 + l f s / x d e b u g . s o x d e b u g . r e m o t e _ e n a b l e=1 x d e b u g . r e m o t e _ p o r t=9 0 0 0 x d e b u g . r e m o t e _ h o s t=l o c a l h o s t Restart your web server once Xdebug has been installed. 2.  Get the DBGp vim script (http://www.vim.org/scripts/script.php?script_id=1929). This will allow vim to act as a debugging client for anything supporting the DBGp protocol ­ such as Xdebug. Create a . v i m / p l u g i n /  directory in your home directory on the server if it doesn't already exist, and extract the d e b u g g e r . p y  and d e b u g g e r . v i m  files into it. Note that for this to work, your vim installation must be compiled with Python support. If you've installed a standard vim package from a package manager you'll probably already have this; if not, install a 'full' vim package rather than a minimal one. To check, type : v e r s i o n  in vim command mode; you should see + p y t h o n  and + s i g n s . These instructions also assume you're running the web server and debug client (vim) on the same machine. If you want to run the debug client on a different machine, you can adjust the xebug.remote_host PHP setting above. 3.  If you're using Firefox, get the Xdebug Helper (https://addons.mozilla.org/en­US/firefox/addon/3960) Firefox extension. This provides you with a small Xdebug icon that lets you turn the Xdebug headers on or off. This appears as an X­in­a­circle logo at the bottom­right of your Firefox window; click on it to turn Xdebug on (the icon will turn yellow­green). If you're not using Firefox, you can turn Xdebug on by appending X D E B U G _ S E S S I O N _ S T A R T = 1  as a URL parameter. For example, w w w . m a g e n t o s t o r e . c o m / h a t s  would become w w w . m a g e n t o s t o r e . c o m / h a t s ? X D E B U G _ S E S S I O N _ S T A R T = 1 . 4.  Once you've got Xdebug started in your browser, either by turning it on using the Firefox extension or by appending to the URL, run vim. Press F5 and you should get a notice saying w a i t i n g   f o r   a   n e w   c o n n e c t i o n   o n   p o r t   9 0 0 0   f o r   5   s e c o n d s . . . . Once you see that, you have five seconds to start a debugging session by sending an Xdebug­enabled request from your browser. Type in the URL you want in your browser, switch to vim, hit F5, then quickly switch to your browser and go to the URL. If you don't get it in time, you'll see a message saying C o n n e c t i o n c l o s e d ,   s t o p   d e b u g g i n g . If this happens, restart vim and try again. If you do get it, you'll see a number of vim windows open and see a message saying:

c o n n e c t i o nf r o m ( ' 1 2 7 . 0 . 0 . 1 ' ,4 4 0 2 7 ) P r e s sE N T E Ro rt y p ec o m m a n dt oc o n t i n u e 5.  Once you have the debugging session up, you can start stepping through the code, setting breakpoints, inspecting variables and everything else you would normally do with a debugger. A full description of how to use a debugger is a bit beyond this article, but here's a quick summary: The current PHP source file is shown on the left; the current line is highlighted in red. Use F2 to step into function calls and F3 to step over them. Breakpointed lines are shown by being highlighted in green. Use the :Bp command to set a breakpoint on the current line. You can open new source files using the :e command, (i.e. : e   / v a r / w w w / m a g e n t o / a p p / M a g e . p h p ), set a breakpoint in them using :Bp and then press F5 to continue execution until the next breakpoint. Use F11 to dump all current context (i.e. function variables) to the window at the top­right. Use F12 to see what's in the PHP variable under the cursor. Use Ctrl­W followed by an arrow key to move between the different vim windows. This can be useful for scrolling up in the watch window.

This debugger is relatively easy to setup and can be very helpful in seeing exactly what's happening as Magento is running. You can debug any action in the Magento frontend or backend, and using breakpoints you can start following execution wherever you want. One very important point to note is that having Xdebug enabled will cause a severe performance hit. Don't forget to disable it when you're done!

Posted by Peter Spiller on Tuesday, July 7th, 2009.
1
Tweet

6

Gosto

0

Comments
Thanks for this blog post. I use Xdebug with PDT for my local development, but it's nice to see an example of usage on the command line.

Anonymous  (http://classyllama.com) Sunday, 16 Aug 2009

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close