In this recipe, we will install and learn how to use Xdebug for debugging our development system.
If you are on a Unix system, type the following command to install Xdebug:
sudo pecl install xdebug
If you are on a Windows system, you can download a compiled DLL from http://www.xdebug.org/ and place it under the ext
directory of your PHP installation.
Then you have to add the mapping in your php.ini
file.
For Unix, add the following mapping:
zend_extension= xdebug.so
And for Windows, add the following mapping:
zend_extension_ts="Absolute_path_of_my_php\ext\my_just_downloaded_dll"
After restarting your web server, you can create a file named phpinfo.php
that contains the following:
<?php phpinfo(); ?|
Place this file at the root of your web server and browse to it. If everything is fine, the Xdebug extension should appear twice. The first one as a Zend extension, and the second as a PHP extension.
You now have an improved var_dump ()
function and your error messages from PHP. Of course, this only works if the Show errors option is turned on.
We assume that you already have an Eclipse instance up and running; if not, go to http://www.eclipse.org/downloads/ and get the latest version (Juno SR1). Then install the PHP Development Tools (PDT) in Eclipse by navigating to Help | Install new software and search for PDT
.
When PDT and Eclipse are successfully installed in your development environment, add the following lines after the zend_extension
line added in your php.ini
file (See the Getting ready section).
xdebug.remote_enable=On xdebug.remote_host="localhost" xdebug.remote_port=9000 xdebug.remote_handler="dbgp"
Once again, restart your web server. In Eclipse, the only setting you have to change is in the Debug Configurations window of PHP applications: set XDebug instead of Zend Debugger in the Server Debugger drop-down menu.
Hit the Apply button and then the Debug button on the same page. Eclipse will open a debug view like it does for any Java applications. In this debug view, you will be able to see and modify variables at runtime and show/add breakpoints.
If you have followed all the previous steps, Xdebug will now control the execution of your PHP programs. It means that it can pause and restart the execution of any program. When the program is held, Xdebug is able to retrieve any data belonging to the program and modify them, on demand.
Throughout these recipes, you've learned how to use some powerful tools that will help you debug your Magento during the development period. Do not forget to disable all debugging options when you put your website into production, such as Xdebug or the template path hints.
With Instant Magento Performance Optimization How-to, you are all set to complete the non-trivial and complex task of performance optimization. Indeed, you have made our Magento go at the speed of light by reducing the time to display a page by almost 75 percent. You are also ready to cluster your own environment. Moreover, you've now learned tools that can help you locate the problems in your Magento installation.
I would like to give you my heartfelt thanks for reading this book and hope that there are more satisfied customers out there.