Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1

(^122) CHAPTER 8 ■ TESTING, DEPLOYMENT, AND CONTINUOUS INTEGRATION
You could also call the xdebug_get_function_stack() method, which returns an array of
information about the function calls up to this point. This function is similar to the standard
debug_backtrace() PHP function.
If you need to determine all the functions and methods that are called between two points
in a script, such as when execution enters another component, you can use Xdebug function
traces. These traces record all the calls to a file for later review. Start and stop a function trace
as follows:
void xdebug_start_trace(string filename [, int options]): This function begins tracing
function calls. The options value is a bitmask that allows you to append trace files using
the XDEBUG_TRACE_APPEND constant, create a computerized output format with XDEBUGTRACE
COMPUTERIZED, or even create an HTML format table trace with XDEBUG_TRACE_HTML.
void xdebug_stop_trace(): When you want the trace to stop, call this function. If you do
not call stop, the trace will end automatically when execution finishes.
Listing 8-9 shows how to trace a method call. This example modifies the previous one by
wrapping the final call in tracing statements.
Listing 8-9. Tracing with xdebug_start_trace
xdebug_start_trace('trace');
$a->myCaller($b);
xdebug_stop_trace();


TRACE START [16:53:57]

0.0010 57964 -> MyClass->myCaller() /code/xdebug.php:21
0.0011 58104 -> MyOther->myCallee() /code/xdebug.php:4
0.0011 58104 -> xdebug_call_class() /code/xdebug.php:10
0.0011 58128 -> printf() /code/xdebug.php:10
0.0014 58196 -> xdebug_call_function() /code/xdebug.php:11
0.0015 58196 -> printf() /code/xdebug.php:11
0.0016 58196 -> xdebug_call_file() /code/xdebug.php:12
0.0016 58244 -> printf() /code/xdebug.php:12
0.0017 58244 -> xdebug_call_line() /code/xdebug.php:13
0.0017 58244 -> printf() /code/xdebug.php:13
0.0018 58244 -> xdebug_stop_trace() /code/xdebug.php:22
0.0019 58244
TRACE END [16:53:57]

Xdebug also allows you to get the current and peak memory utilization of a script and the
time the script has taken since it started running.

McArthur_819-9C08.fm Page 122 Friday, February 22, 2008 9:06 AM

Free download pdf