| 1 |
Installation
|
| 2 |
------------
|
| 3 |
|
| 4 |
/**
|
| 5 |
* REQUIREMENTS
|
| 6 |
/*
|
| 7 |
|
| 8 |
You will need to install XDebug in order for this module to work correctly.
|
| 9 |
The installation instructions from XDebug are in Section 2.0.
|
| 10 |
There are some changes that need to be made to your .htaccess and php.ini file,
|
| 11 |
which are detailed in Section 2.1 and Section 2.3.
|
| 12 |
Sections 2.2 & 2.4 lists some checks to verify that you're correctly
|
| 13 |
installing Xdebug.
|
| 14 |
|
| 15 |
If you'd like to dynamically view the GraphViz generated flowcharts, then
|
| 16 |
I recommend to installing the ZGRViewer from the command line (Section 3.0)
|
| 17 |
and changing some apache permissions (Section 4.0).
|
| 18 |
|
| 19 |
Some additional debugging references are listed in Section 5.0 in case you run
|
| 20 |
into any trouble along the way.
|
| 21 |
|
| 22 |
NOTE: These instructions are Mac OS X specific, but it should be possible to get
|
| 23 |
working on Windows or Linux as well.
|
| 24 |
|
| 25 |
|
| 26 |
/**
|
| 27 |
* Section 1.0
|
| 28 |
* Install & enable the visualize_backtrace.module
|
| 29 |
/*
|
| 30 |
1. DOWNLOAD AND INSTALL VISUALIZE BACKTRACE MODULE
|
| 31 |
Visualize Backtrace can be found at
|
| 32 |
http://drupal.org/project/visualize_backtrace/.
|
| 33 |
|
| 34 |
2. ENABLE THE VISUALIZE BACKTRACE MODULE
|
| 35 |
Unpack the module in your site's module directory. Then browse to
|
| 36 |
"administer" -> "site building" -> "modules" OR "admin/build/modules"
|
| 37 |
and enable the Visualize Backtrace module.
|
| 38 |
|
| 39 |
3. CONFIGURE VISUALIZE BACKTRACE MODULE PERMISSIONS
|
| 40 |
Browse to "administer" -> "user management" -> "access control" OR
|
| 41 |
"admin/user/access" & set permissions for "administer visualize backtrace."
|
| 42 |
|
| 43 |
WARNING: Do not enable the 'View Backtrace Graphs' until XDebug is confirmed
|
| 44 |
to be set up properly -- otherwise you risk getting a White Screen of Death.
|
| 45 |
More set-up instructions are in the sections down below.
|
| 46 |
|
| 47 |
/**
|
| 48 |
* Section 2.0
|
| 49 |
* Installing XDebug 2.0
|
| 50 |
/*
|
| 51 |
|
| 52 |
Download XDebug from http://xdebug.org/
|
| 53 |
Below are the installation instructions copied from XDebug's README
|
| 54 |
More XDebug installation references can be found in Section x.x at the bottom
|
| 55 |
|
| 56 |
In a crib note summary, here are the actual commands that I used after copying
|
| 57 |
the downloaded xdebug-2.0.0 folder to /usr/local/bin
|
| 58 |
$ phpize;
|
| 59 |
$ ./configure --enable-xdebug --with-php-config=/usr/bin/php-config;
|
| 60 |
$ make;
|
| 61 |
$ cp /usr/local/bin/xdebug-2.0.0/xdebug-2.0.0/modules/xdebug.so /Users/kent/komodo/extensions;
|
| 62 |
$ Add "zend_extension=/Users/kent/komodo/extensions/xdebug.so" to php.ini;
|
| 63 |
RESTART
|
| 64 |
|
| 65 |
1. Unpack the tarball: tar -xzf xdebug-2.x.x.tgz. Note that you do
|
| 66 |
not need to unpack the tarball inside the PHP source code tree.
|
| 67 |
Xdebug is compiled separately, all by itself, as stated above.
|
| 68 |
|
| 69 |
2. cd xdebug-2.x.x
|
| 70 |
|
| 71 |
3. Run phpize: phpize
|
| 72 |
(or /path/to/phpize if phpize is not in your path).
|
| 73 |
|
| 74 |
4. ./configure --enable-xdebug (or: ../configure --enable-xdebug
|
| 75 |
--with-php-config=/path/to/php-config if php-config is not in your
|
| 76 |
path)
|
| 77 |
|
| 78 |
5. Run: make
|
| 79 |
|
| 80 |
6. cp modules/xdebug.so /to/wherever/you/want/it
|
| 81 |
|
| 82 |
7. add the following line to php.ini:
|
| 83 |
zend_extension="/wherever/you/put/it/xdebug.so"
|
| 84 |
|
| 85 |
8. Restart your webserver.
|
| 86 |
|
| 87 |
9. Write a PHP page that calls "phpinfo();" Load it in a browser and
|
| 88 |
look for the info on the xdebug module. If you see it, you have been
|
| 89 |
successful!
|
| 90 |
|
| 91 |
|
| 92 |
/**
|
| 93 |
* Section 2.1
|
| 94 |
* Change the PHP.ini
|
| 95 |
/*
|
| 96 |
As described in step #7 above, be sure that
|
| 97 |
"zend_extension=/usr/local/xdebug/xdebug.so" has been added to your php.ini file
|
| 98 |
-- which on my computer is located at /usr/local/php5/lib/php.ini
|
| 99 |
|
| 100 |
|
| 101 |
/**
|
| 102 |
* Section 2.2
|
| 103 |
* Verify that XDebug correctly installed
|
| 104 |
/*
|
| 105 |
Go to /admin/logs/status/php to verify & search for XDebug to verify that it
|
| 106 |
has been correctly installed.
|
| 107 |
|
| 108 |
/**
|
| 109 |
* Section 2.3
|
| 110 |
* Add lines to your .htaccess file to generate XDebug trace logs
|
| 111 |
/*
|
| 112 |
|
| 113 |
The XDebug traces should have auto_trace turned on, trace_format of 1,
|
| 114 |
and the trace_output_name should be the timestamp.
|
| 115 |
|
| 116 |
To set all of this up, then open up your .htaccess file (which will most likely
|
| 117 |
be hidden), and add in the following lines:
|
| 118 |
|
| 119 |
# via http://www.sitepoint.com/blogs/2007/04/23/faster-php-apps-profile-your-code-with-xdebug/
|
| 120 |
php_value xdebug.profiler_output_dir /tmp
|
| 121 |
php_value xdebug.profiler_output_name timestamp
|
| 122 |
php_value xdebug.profiler_enable 1
|
| 123 |
php_value xdebug.auto_trace 1
|
| 124 |
php_value xdebug.trace_format 1
|
| 125 |
php_value xdebug.trace_output_name timestamp
|
| 126 |
|
| 127 |
** NOTE: For XDebug 2.0, the "timestamp" may need to be changed to "trace.%t" to
|
| 128 |
get the trace files into the format of /tmp/trace.1191258238.xt --
|
| 129 |
(i.e. where the trace file number is equal to the timestamp of the page load)
|
| 130 |
|
| 131 |
/**
|
| 132 |
* Section 2.4
|
| 133 |
* Verify that XDebug is correctly generating trace logs
|
| 134 |
/*
|
| 135 |
After enabling the visualize_backtrace.module & user access permissions in
|
| 136 |
Section 1.0, then go to the path "/test_xdebug" to test whether or not the
|
| 137 |
trace files are correctly being generated.
|
| 138 |
|
| 139 |
If it is not set up correctly, then you will see this:
|
| 140 |
"XDebug is not properly creating trace files yet. Check the INSTALL.txt
|
| 141 |
for more debugging information.';"
|
| 142 |
|
| 143 |
This debugging information can be found in the reference Section 5.0 down below.
|
| 144 |
|
| 145 |
If it is set up correctly, then you will see this:
|
| 146 |
"XDebug is properly creating trace files located at: /tmp/trace.1192237296.xt"
|
| 147 |
|
| 148 |
And when you open up the trace file, then you should see something like this:
|
| 149 |
Version: 2.0.0RC3
|
| 150 |
TRACE START [2007-10-13 01:01:36]
|
| 151 |
1 0 0 0.000681 57384 {main} 1 /Library/WebServer/Documents/d52/index.php 0
|
| 152 |
2 1 0 0.005755 259384 require_once 1 /Library/WebServer/Documents/d52/includes/bootstrap.inc /Library/WebServer/Documents/d52/index.php 12
|
| 153 |
3 2 0 0.005795 259844 define 0 /Library/WebServer/Documents/d52/includes/bootstrap.inc 13
|
| 154 |
3 2 1 0.005827 259844
|
| 155 |
3 3 0 0.005842 259844 define 0 /Library/WebServer/Documents/d52/includes/bootstrap.inc 18
|
| 156 |
|
| 157 |
...
|
| 158 |
|
| 159 |
3 2899 0 0.364787 9936352 variable_get 1 /Library/WebServer/Documents/d52/sites/all/modules/devel/devel.module 405
|
| 160 |
3 2899 1 0.364820 9936352
|
| 161 |
2 2898 1 0.364847 9935244
|
| 162 |
1 2880 1 0.364884 9933716
|
| 163 |
0.3790 41492
|
| 164 |
TRACE END [2007-10-13 01:01:37]
|
| 165 |
|
| 166 |
/**
|
| 167 |
* Section 2.5
|
| 168 |
* Enable the 'View Backtrace Graphs' block
|
| 169 |
/*
|
| 170 |
After verifying that the trace logs are being generated in the correct format,
|
| 171 |
then you can now enable the 'View Backtrace Graphs' block at the path
|
| 172 |
"/admin/build/block"
|
| 173 |
|
| 174 |
This is the easiest & quickest way to generate backtrace graphs for a given
|
| 175 |
page load.
|
| 176 |
|
| 177 |
You can also start to view all of the past trace files at the path
|
| 178 |
"/view_traces"
|
| 179 |
|
| 180 |
|
| 181 |
/**
|
| 182 |
* Section 3.0
|
| 183 |
* Install ZGRViewer to view the *.dot flowcharts
|
| 184 |
/*
|
| 185 |
|
| 186 |
The ZGRViewer is by far the best way to view the huge *.dot flowcharts that are
|
| 187 |
generated. It can be a little tricky to set up, but here are the steps that I
|
| 188 |
took to get it up and running.
|
| 189 |
|
| 190 |
1.) Download ZGRViewer from http://zvtm.sourceforge.net/zgrviewer.html#download
|
| 191 |
Or go directly to http://sourceforge.net/project/showfiles.php?group_id=63244
|
| 192 |
And download the latest version of zgrviewer (release 0.7.2a as of 10/12/07)
|
| 193 |
|
| 194 |
2.) Unzip the zgrviewer-0_7_2a.zip package and copy the "zgrviewer" folder to
|
| 195 |
/usr/local/bin/zgrviewer. If you drag and drop it using the Finder, then you'll
|
| 196 |
have to authenticate the move. You can alternatively save it in your preferred
|
| 197 |
location for unix programs.
|
| 198 |
|
| 199 |
3.) OPTIONAL: If you want to be able to launch the ZGRViewer directly from
|
| 200 |
Drupal, then you need to be sure that all of the you have the proper owner and
|
| 201 |
group permissions of all of the zgrviewer files.
|
| 202 |
|
| 203 |
- Open the terminal.
|
| 204 |
$ cd /usr/local/bin/zgrviewer
|
| 205 |
|
| 206 |
- Double check your username
|
| 207 |
$ whoami
|
| 208 |
|
| 209 |
- Check to see that the owner and group is under your username,
|
| 210 |
and not "root" or "wheel"
|
| 211 |
$ ls -l
|
| 212 |
|
| 213 |
- If it isn't under your name, then change the permissions on all of the files
|
| 214 |
$ sudo chown your_username:your_username *.*
|
| 215 |
|
| 216 |
4.) The ZGRViewer requires some library information from GraphViz. Download
|
| 217 |
the GraphViz Mac client viewer from http://www.pixelglow.com/graphviz/ and
|
| 218 |
install into your Applications folder. Or alternatively you can download the
|
| 219 |
unix source code from http://www.graphviz.org/Download.php (after scrolling to
|
| 220 |
the bottom and agreeing to the license)
|
| 221 |
|
| 222 |
5.) To run ZGRViewer for the first time, then open up a terminal window and
|
| 223 |
$ cd /usr/local/bin/zgrviewer
|
| 224 |
$ ./run.sh
|
| 225 |
|
| 226 |
6.) Go to SETUP: View -> Preferences -> Directories
|
| 227 |
Enter in the following information (be sure to replace "kent" with
|
| 228 |
your own username)
|
| 229 |
|
| 230 |
Temporary Directory=
|
| 231 |
/tmp
|
| 232 |
|
| 233 |
DOT files directory =
|
| 234 |
/Users/kent/Documents/GraphViz
|
| 235 |
|
| 236 |
GraphViz/dot executable =
|
| 237 |
/Applications/Graphviz.app/Contents/MacOS/dot
|
| 238 |
|
| 239 |
GraphViz/neato executable =
|
| 240 |
/Applications/Graphviz.app/Contents/MacOS/neato
|
| 241 |
|
| 242 |
GraphViz/circo executable =
|
| 243 |
/Applications/Graphviz.app/Contents/MacOS/circo
|
| 244 |
|
| 245 |
GraphViz/twopi executable =
|
| 246 |
/Applications/Graphviz.app/Contents/MacOS/twopi
|
| 247 |
|
| 248 |
GraphViz font directory (optional) =
|
| 249 |
/library/fonts
|
| 250 |
|
| 251 |
7.) In order to view ZGRViewer HREF links from a rendered *.dot file, then you
|
| 252 |
must go to
|
| 253 |
View -> Preferences -> Web Browser
|
| 254 |
Specify Browser with the following Command Line Options --
|
| 255 |
enter "open -a /Applications/Safari.app" to use Safari or
|
| 256 |
"open -a /Applications/Firefox.app" to use Firefox
|
| 257 |
Do a File -> Reload to initialize the settings
|
| 258 |
Highlight Node by hovering over a mouse & Hit either the 'L' key
|
| 259 |
or the Space Bar
|
| 260 |
|
| 261 |
Note: In order to execute the following CLI command with shell_exec() from
|
| 262 |
Drupal, then you may have to change some apache httpd.conf permissions as
|
| 263 |
detailed in Section 4.0.
|
| 264 |
If you are not comfortable with giving Drupal your user's UNIX permissions,
|
| 265 |
then copy & paste the generated command line interface commands directly
|
| 266 |
into the terminal
|
| 267 |
(i.e. /usr/local/bin/zgrviewer/run.sh --Pdot /Library/WebServer/Documents/d52/files/1191949882_section1.dot; )
|
| 268 |
|
| 269 |
|
| 270 |
/**
|
| 271 |
* Section 4.0
|
| 272 |
* Change some Apache permission settings
|
| 273 |
/*
|
| 274 |
|
| 275 |
If you want to automatically launch the ZGRViewer from Drupal, then you have to
|
| 276 |
change a permission in the httpd.conf file that can be found at
|
| 277 |
/etc/httpd/httpd.conf
|
| 278 |
|
| 279 |
CHANGE FROM
|
| 280 |
User www
|
| 281 |
Group www
|
| 282 |
|
| 283 |
CHANGE TO
|
| 284 |
User your_username
|
| 285 |
Group your_username
|
| 286 |
|
| 287 |
Do a $ whoami in a terminal window to determine your_username if you don't
|
| 288 |
know it
|
| 289 |
|
| 290 |
NOTE: This is probably not the ideal solution due to security concerns (i.e.
|
| 291 |
Drupal command-line interface commands could execute UNIX commands with
|
| 292 |
whatever permissions your username has). But you should be safe if you are
|
| 293 |
running it locally on your computer, and if you're sure to double check all the
|
| 294 |
CLI commands that will be running from shell_exec() in the future.
|
| 295 |
For more discussion on this see here:
|
| 296 |
http://us3.php.net/manual/en/function.shell-exec.php#37971
|
| 297 |
As well as here: http://www.webhostingtalk.com/archive/index.php/t-386461.html
|
| 298 |
|
| 299 |
|
| 300 |
/**
|
| 301 |
* Section 5.0
|
| 302 |
* References
|
| 303 |
/*
|
| 304 |
|
| 305 |
Below is a brief summary of some XDebug references that I used to get it up and
|
| 306 |
running. The latest updated version is here: http://del.icio.us/kentbye/xdebug
|
| 307 |
|
| 308 |
* * * *
|
| 309 |
Xdebug .htaccess Settings to enable complete function call traces within PHP/Drupal
|
| 310 |
http://xdebug.org/docs/all_settings#trace_format
|
| 311 |
Add this to .htaccess file: php_value xdebug.profiler_output_dir /tmp
|
| 312 |
* php_value xdebug.profiler_output_name timestamp
|
| 313 |
* php_value xdebug.profiler_enable 1
|
| 314 |
* php_value xdebug.auto_trace 1
|
| 315 |
* php_value xdebug.trace_format 1
|
| 316 |
|
| 317 |
* * * *
|
| 318 |
Remote PHP Debugging on Intel-based Macs with Komodo IDE | SysArchitects
|
| 319 |
http://www.sysarchitects.com/node/22
|
| 320 |
Finally got this to work w/ custom compiled xdebug.so placed in
|
| 321 |
/Users/kent/komodo/extensions & Wizard created php.ini in /Users/kent/komodo/ini
|
| 322 |
(/usr/local/php5/lib/php.ini) & typing "?XDEBUG_SESSION_START=1" into firefox
|
| 323 |
URL. Very painful to get working
|
| 324 |
|
| 325 |
* * * *
|
| 326 |
Xdebug - Debugger and Profiler Tool for PHP
|
| 327 |
[via http://www.sysarchitects.com/node/22] --
|
| 328 |
Place in /usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613
|
| 329 |
http://xdebug.org/
|
| 330 |
|
| 331 |
phpize;
|
| 332 |
./configure --enable-xdebug --with-php-config=/usr/bin/php-config;
|
| 333 |
make;
|
| 334 |
cp /usr/local/bin/xdebug-2.0.0/xdebug-2.0.0/modules/xdebug.so /Users/kent/komodo/extensions;
|
| 335 |
Add "zend_extension=/Users/kent/komodo/extensions/xdebug.so" to php.ini;
|
| 336 |
RESTART
|
| 337 |
|
| 338 |
* * * *
|
| 339 |
Squash bugs in PHP applications with Xdebug
|
| 340 |
http://www.ibm.com/developerworks/library/os-php-xdebug/index.html
|
| 341 |
A relatively new article on XDebug from IBM (8/7/07)
|
| 342 |
|
| 343 |
* * * *
|
| 344 |
Xdebug Development List: By Date
|
| 345 |
http://xdebug.org/archives/xdebug-dev/date.html
|
| 346 |
XDebug development e-mail list
|
| 347 |
|
| 348 |
* * * *
|
| 349 |
Xdebug Trace_Format Output Column numbers
|
| 350 |
http://xdebug.org/docs/execution_trace#trace_format
|
| 351 |
XDebug trace output $1 = level, $2 = function_number, $3 = always_zero,
|
| 352 |
$4 = time_index, $5 = memory, $6 = function_name,$7 = defined_function,
|
| 353 |
$8 = via_filename,
|
| 354 |
if ($10 exists) then {
|
| 355 |
$9 = included_file; $10 = line_number;
|
| 356 |
} else {
|
| 357 |
$9 = line_number}
|
| 358 |
|
| 359 |
More GraphViz references can be found here: http://del.icio.us/kentbye/graphviz
|
| 360 |
|
| 361 |
|
| 362 |
// $Id$
|