Home arrow PHP arrow Page 2 - Tracking a Stack of Function Calls with the Xdebug Extension

Review: the xdebug_time_index() function - PHP

If you’re a PHP programmer looking for a comprehensive guide to using the most relevant functions that come with the X-debug extension, then this set of articles might be what you need. Welcome to the last part of a series focusing on debugging in PHP with the Xdebug extension. In seven approachable parts, this series gets you started utilizing this library's numerous features by way of a hands-on approach.

TABLE OF CONTENTS:
  1. Tracking a Stack of Function Calls with the Xdebug Extension
  2. Review: the xdebug_time_index() function
  3. Retrieving information with the xdebug_get_function_stack() function
  4. Displaying the contents of the stack of function calls
By: Alejandro Gervasio
Rating: starstarstarstarstar / 2
March 16, 2009

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

First, I'd like to quickly review the practical example developed in the preceding article of this series, in case you haven't had a chance to read that article. The example was aimed at demonstrating how to use the “xdebug_time_index()” function for building a pair of timing scripts.

That being said, here are the two code samples that create those timing scripts. Have a look at them, please:

(example on using the 'xdebug_time_index()' function within a procedural script)


echo 'Starting time : '.xdebug_time_index().'<br />';

for($i=0;$i<=3;$i++){

// do nothing

sleep(1);

}

echo 'Total script execution time : '.xdebug_time_index();


/* displays the following


Starting time : 0.001168966293335

Total script execution time : 3.9993019104004

*/



(example on using the 'xdebug_time_index()' function within an object-based script)


class Timer{

public function __construct(){}

public function getTime(){

return xdebug_time_index();

}

}


$timer=new Timer();

echo 'Starting time :'.$timer->getTime().'<br />';

for($i=0;$i<=5;$i++){

sleep(1);

}

echo 'Total script execution time :'.$timer->getTime();

/* displays the following


Starting time :0.0012168884277344

Total script execution time :5.9927868843079


*/


As you can see, the examples listed above illustrate how to use the “xdebug_time_index()” function to build a few primitive timing applications. In the first case, the function is utilized in the context of a procedural script, while the second example is a bit more interesting, since it shows how to create a basic timer class by using the function. Quite simple to grasp, right?

Hopefully, at this point you already realized how useful the “xdebug_time_index()” function can be when it comes to calculating the execution time of a certain PHP application. So what's next? Well, as I said in the introduction, the Xdebug extension includes yet another handy function, named “xdebug_get_function_stack(),” that permits us to explore with relative ease the stack of function calls generated when a script is parsed by the PHP engine.

Therefore, in the next section I’ll be explaining how to use this function in a concrete situation. In fact, I'll use a hands-on example to demonstrate it explicitly. This way, you can get a better idea of its actual functionality.

To learn how this brand new example will be developed, go ahead and read the next segment. It’s only one click away.



 
 
>>> More PHP Articles          >>> More By Alejandro Gervasio
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: