php---which tool i can use to trace a cms source code - php

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.

Related

Using Eclipse to see where a function was called or class used

I am using Eclipse with PHP and I am trying to trace back the calls functions and instantiations of classes to see why a certain piece of code was used.
The Eclipse interface is a bit cluttered. How do I see the function call trace? Is that possible to do?
Thanks,
Alex
A possibily good solution would be to use a debugger, in step-by-step mode -- or by setting a breakpoint where you want to see the call-trace.
This will allow you to see variables and the call trace / history -- and, also, to go line by line into your source-code's execution.
About debugging and Eclipse, the following question + answers should be able to help : Good Free PHP debugger?
This post of me can't be actually a solution but just wanted to share.
In addition to what's already answered (which enables call trace during runtime), PHP plugin of Eclipse called PDT has a feature called Call Hierarchy. However, it looks like this feature has not been implemented as of the latest version 3.1.
This is why I said my post isn't an answer, but I'm hoping that spreading the words like this would motivate the PDT enter code hereplugin developers.
What you probably want is the Parameter stack, found in Show view under PHP Tools and Parameter stack.

Can anybody suggest a good Debugging package for PHP?

I use firebug and smarty so i get good debugging data from that but i'd like to see my database query times and page processing times as well.
Xdebug is very good. It works very well in combination with Netbeans IDE for PHP.
This is a great package to relay data to firebug:
http://www.firephp.org
xdebug is awesome, because it lets you step through code inspecting variables as you go.
It also lets you do profiling (dumps callgrind files into a directory of your choosing, describing in very detailed fashion what happened how many times, when, and how long everything took)
To take full advantage of xdebug, you need a good IDE, i suggest netbeans, but you can use any one of the major packages nowadays.
As linked many times by others, FirePHP and Xdebug are awesome...
But you also asked about page render times and query times.
Unless you're already using a framework that collects this data for you, you're going to need to collect it and set up reporting for it yourself.
Debugging PHP Code on Windows with Visual Studio 2008 or 2010 => http://www.jcxsoftware.com

is there a way to see what code is executing when revoking a method?

to learn a library/framework i think the best way would be to use a class method and then see what code is executing in live.
then you see the method chain (input and output of each) and can also read the comments.
is there a such feature in any IDE or external application for php?
Is that so called Debugger?
You can install ZendDebugger or XDebug in your IDE and trace through the code.
I use xdebug with netbeans. it's working great for me. I had a blog post about it. if you are interested, may have a read. http://blog.elinkmedia.net.au/2010/02/08/netbeans-debugger-with-zend-framework/

How to do Debugging of PHP?

how we do basic debugging in PHP ?
Can anybody share true horror story on debugging PHP application (or (even better) on PHP framework such Codeigniter and Wordpress) ?
i love to hear real experience in case i have to encounter similar situation on my journey to learn PHP.
XDebug may be used to debug a PHP application. Basically you install this on your server and configure it in PHP.ini. Then on your desktop machine, you can setup Netbeans (and maybe Eclipse, but I have not tried that) to remote debug. When you are in a remote debug session you can do any of the things you typically expect: set breakpoints, step through code, etc.
One major annoyance when using CodeIgniter with mod_rewrite is that the debugger gets confused by index.php not showing up in the URL. I am not sure if this is a problem on the client side or server, and whether CI "eating" the GET portion of a URL has anything to do with it. In any case, I have worked through it by copying a 'debug.php' file to the server and starting debugging with that file - everything seems to work fine after that.
I any case, I highly recommend you get setup with XDebug at some point. You may not use it everyday, but when you need it you'll be thankful you did your homework ahead of time.
Easiest option (without installing any IDE) is to use firefox FirePHP addon.
Download and install FirePHP firefox addon
Download FirePHP core library from their website
Extract FirePHP library you downloaded in step 2 and only copy FirePHP.class.php to CodeIgniter /application/libraries/ folder, but give it a name FirePHP.php without the class part
Turn PHP’s output buffering on
Start your Firefox, click the FireBug icon on the bottom lower area, or go to menu and select tools. After you turn on (set them to enable) FireBug and FirePHP, be sure to click on the Net tab next in line to HTML, CSS, Script, DOM and set it also to enable.
See this link for how to use firephp library: http://speedtech.it/2009/05/debugging-a-codeigniter-application-with-firephp/
There is one problem in using IDE debugers - it's bad for debuging AJAX applications. In this case you will need to use some of browser extension. For FireFox it's FirePHP, and gor Google Chrome it's Php console.
I checked out a lot of debuggers 2 years ago when I wanted to set up a debugging environment for myself in PHP. I posted a brief post on this, you can go through it http://forums.codewalkers.com/general-chat-93/which-php-ide-to-use-840352.html
Bottomline was that Nusphere's phped was the best and its debugbreak() function makes debugging a real bliss. With codeigniter also this works fine, no tweaks required if you have already enabled get variable. The only hiccup with codeigniter+phed is that, you cannot do code navigation like "right click and find declaration" for other files models.
Off late I have been checking out codelobster they have a codeigniter plugin, but I am not through with it yet.

Find PHP Orphan Page

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.

Categories