I looked for ideas on setting up a Magento development environment when we first started using it for our site last year. I didn't find anything that work really well, so I stayed with var_dump'ing using the log files.
Now that Magento has another year under its belt and several hundred more developers I was wondering if anyone has found a better solution for debugging Magento.
We use Eclipse as our development environment. We tried a pre-2.0 release of PDT with the Zend Debugger and didn't have much luck.
How about using FirePHP?
http://ajzele.net/utilize-firebug-and-firephp-to-speed-up-magento-development
It made my life a hell of a lot easier.
I use a combination of var_dump with xDebug and Magento's Mage::Log method. Mage::Log is particularly nice, as it'll do some auto-expanding and pretty printing of objects if you pass them in (I'm not sure if that's the logger, or just Magento's __toString implementation).
If I'm on my local development box I use Console.app to keep an eye on the log file, otherwise it's a simple
tail -f /path/to/log/file
That combined with some custom modules I've built for debugging the config and layout keep me happy. (although I prefer a light weight text editor toolchain vs. the One True IDE tool chain, so your results may vary)
logging $object->getData() rather than the $object itself is normally more useful, and everything built into Magento has it as a method (everything extends Varien_Object)
$object->debug() is often quite helpful too, although it doesn't exist on all objects.
Here are my most commonly logged statements:
Mage::log( $object->debug() )
Mage::log( $object->getData() )
Mage::log( get_class($object) ) # name of class
Mage::log( get_class_methods($object) ) # methods of class
I also use FirePHP but find this extension easier.
Give it a try to Magneto-Debug: https://github.com/madalinoprea/magneto-debug (only for dev environments).
Video doesn't contain features added in the latest version: http://www.youtube.com/watch?v=aqvgrmebcu4
- display layout updates from DB
- display blocks' rendering time
NuSphere is also good debugger for magento here is link
NuSphere
Related
I love to save time using someone else's code. And I want to start effectively debugging my scripts, as well as scripts I inherit from other developers.
I've been reading up on debug_backtrace(), and I'm not sure if it's what I'm looking for.
Basically,when a class is instantiated I want to know what methods are being fired.
Truthfully, I'd like to know as much as possible, but knowing what's going on inside a single class would be fantastic.
<?php
require('aHugeComplicatedClass.php'); // sooooo many methods
try {
$obj = new aHugeComplicatedClass($params);
}
catch(Exception $ex){
var_dump($ex);
}
?>
From PHP's docs about debug_backtrace, it looks like I need to place the debug_backtrace() function inside each method/function within any and all classes, just to see how it was reached.
I gotta be reading this too literal. That would be a ton of modifications.
So, if I have a php file, that instantiates a class, and I know this class is extended from other classes, what's the simpliest way to debug that Object?
I would install XDebug and hook up the remote debugging to your IDE (e.g PhpStorm or Eclipse), that way you will get nice stack dumps on all errors, plus the ability to breakpoint your code and inspect the stack and all object internals at your leisure.
http://xdebug.org/
You can also use it to profile your application call chains without making any code changes (which sounds more like what you are wanting). By using the profiling options, which generate big log files, you can then load these logs into webgrind and visually inspect who's calling what in nice tree structures.
https://code.google.com/p/webgrind/
The Zend tool chain would also provide this kind of deeper debugging functionality out of the box.
Alternatively install an Application Performance Monitoring agent such as App Dynamics or New Relic for similar code-profiling. This is most useful for remote installations (i.e. production) where debugging isn't an option and profiling is expensive.
We use NuSphere PhpED for getting all such things. It can trigger debugger to stop on specified exceptions and/or errors and shows complete call-stack that may include php functions calls, php method calls, embedded functions calls and embedded method calls.
http://www.nusphere.com/products/phped.htm
I was told in the beginning that their debugger is the best and can confirm this. It stems from the OSS project
http://sourceforge.net/projects/dbg2/
With PhpED IDE we run full cycle of development -- coding, debugging, profiling, testing and uploading to the production server.
Problem
I have a legacy codebase I need to analyze and determine dependencies. Particularly the dependencies on classes (internal/external) and extensions (Memcache, PDO, etc).
What I've Tried
I have reviewed the tools listed in Is there a static code analyzer for PHP files?. Unfortunately, this post is dated and most of the promising tools like phpCallGraph no longer work.
My thought was to analyze the code lexically and look for class tokens. Reviewing a list of these would at least allow me to visually determine dependencies. However finding OtherClass in the following code may be complex:
$classname = 'OtherClass';
echo $classname::doubleColon();
In the end, I doubt I'm the first to need this. I'm sure a tool or combination of tools exist to provide what I need. So I'm asking the SO community before writing this myself.
Update
Ideally this tool will analyze multiple files with complete code coverage. As such, tools like Xdebug, while great, are not solutions to this exact problem.
Instead of phpCallGraph you could use Gopal Vijayaraghavan's inclued extension which in combination with Graphviz gives you a nice looking graph of all included files for a certain execution path.
Example:
Moreover, I'd recommend Xdebug (a PHP debugger) which offers a profiler that outputs data consumable by Valgrind. Use the debugger with a compatible IDE to follow the execution path (which helped me a lot to wade thru e.g. Drupal's massive call-stack).
Combine both and you should get a fairly thourough overview.
EDIT
Searched the web and found nWire for PHP - an eclipse plugin that looks like it could be the right tool for you (30 day free trial which should be enough to give you a head start).
I think PhpCodeAnalyzer is exactly what you're looking for - https://github.com/wapmorgan/PhpCodeAnalyzer
It print list of all used external extensions in code base.
I'm starting a new project, for this project, I need a great IDE, which allows me to debug. I thought to aptana after some search.
But this project is a little specific, it has to work with a specific version of php and has not common extension(e.g. php_ingres), so I think I cannot use the internal server of aptana, otherwise it will not find every ingres function.
I've an EasyPhp environnement installed and working.
I've created a new "Simple server" and a new web browser configuration using this webserver(and chrome). But now when I try to debug it, I cannot see my browser configuration, it looks like it display only internal servers here. So is this possible to use aptana with easyphp? If yes, how?
If not, which IDE provide some auto-completion, debugging and allows me to use my own server?
Thank you very much
I think Netbeans can do your job, check this guide :
http://wiki.netbeans.org/HowToConfigureXDebug
Netbeans is great and is free too. But it maybe hard to figure your way around in that for a 1st time user. If money ain't a problem i'd suggest using phpDesigner 7 - http://www.mpsoftware.dk/phpdesigner.php. Easy and simple, with word completion, debugging features and also allows you to setup up an FTP connection to your servers so you can edit your files on the fly.(This method of editing files on the fly however may not be ideal if its mission critical data. I'd suggest using version control platforms like git, read more here - http://progit.org/book/ch1-1.html )
I finally used code lobster, which is not the best editor but can use easyPhp and actually debug into it.
now, if i want to trace the drupal sourcecode.how and which tool i can use to trace the drupal source code?i want to make a quick walk-through to drupal code. and want to trace it myself,but i don't know which good debugger i should use and how to trace it, thank you
xdebug is an extension to PHP.
With it, you can get a Trace file every time a page is loaded, with a full list of every function called while rendering that page.
http://www.xdebug.org/docs/execution_trace
Try Drupal for Firebug http://drupal.org/project/drupalforfirebug with firebug https://addons.mozilla.org/de/firefox/addon/1843/ as addon in firefox
A quick and dirty way to find which methods was used and what values been passed until certain moment can be archived by outputting debug_backtrace()
like:
var_dump(debug_backtrace());
There are many IDE with integrated debuggers at most they work same way, as example above.
You can try Eclipse or NetBeans for free or Zend Studio for a fee.
Have you played much with the API Documentation? All of the core code is documented here, as well as providing a hyperlinked snapshot of the current HEAD for the particular major version you are browsing. One you get a good grasp of how hooks and templates work, tracing through code this way is mostly easy.
I've inherited a PHP application that has "versions" of pages (viewacct.php, viewacct2.php, viewacct_rcw.php, etc). I want to discover which of these pages are called from other pages in the application and which are not. Is there a tool available that will help with that?
Using whatever tools you would like (Find/Grep/Sed on Linux, I use Visual Studio on windows), it is just a matter of crawling your source tree for references of the filenames in each file.
Similar to FlySwat's answer: any good text editor or IDE with multi-file search should be able to help you find the orphan pages. On Mac OS X I would suggest TextWrangler(free), TextMate($), or BBEdit($$). I've had good success with each of these tools, but your mileage may vary.
If you wish to find out what pages are called by other pages, you need to look at where stuff is being called. Obviously in php code, you can only reference other files via includes or requires and the singular versions of those functions.
So if I were you I would grep your code for include and then require and attempt to make some kind of map showing what is calling what. Eventually you should end up with a pretty clear map of how the php files talk to each other. Then you will need to work out how the various points of the application talk to each other from there via HTML/AJAX etc.
Good luck. I have done it before, it takes a while, but you'll get there, just make sure you document what you find out.
You may want to try out nWire for PHP.
nWire for PHP is an innovative Eclipse plugin (works with Eclipse PDT & Zend Studio 7) which accelerates PHP development by helping developers navigate through their code and better understand the architecture of their application. nWire offers unique tools for real time code visualization, navigation and search.
nWire analyzes all the components and associations in your project. While opening a file you can immediately see where (and if) it is being used.