background preloader

Xdebug

Facebook Twitter

Xdebug Quickstart: Profiling in PHP | Team Lazer Beez Blog. Preface There are numerous ways to evaluate the performance of a PHP script. The simplest, our good friend microtime, allows you to do targeted benchmarking of certain sections of code: $startTime = microtime(true); functionCall();$timeDiff = microtime(true) - $startTime; echo 'functionCall() took '. $timeDiff .' seconds'; This works extremely well for quickly testing the performance of a specific piece of code. Lack of granularity – You only get one number, which is the total amount of time taken between the start and stop points.

Thankfully, there are helper classes for this, like PEAR_Benchmark. But fear not, dear reader, for there is a better way! The Joy of Profiling What does profiling buy you? Total request timeTime spent in every function that was hit during the request (either in absolute time or as a percentage of the request)Number of times each function was called over the course of the requestRainbows bursting forth from your monitor! It’s Not Just A Debugger. Introducing xdebug. By: Stefan Priebsch Other Articles in the Series Part One: Introducing xdebugPart Two: Tracing PHP Applications with xdebugPart Three: Profiling PHP Applications With xdebugPart Four: Debugging PHP applications with xdebugPart Five: Creating Code Coverage Statistics with xdebug This article is the first installment of a five-part series of articles covering xdebug, a free and open source swiss army knife tool for PHP developers.xdebug is a PHP extension created by Derick Rethans, one of the PHP core developers.

This week, we will show you how to install xdebug and introduce you to some of the basic features. In the subsequent parts of this article series, we will have a closer look at one of xdebug’s main features, namely tracing, profiling, debugging, and code coverage. Installing the xdebug extension First of all, we need to install xdebug. Xdebug does not work with any PHP versions before 4.3, and will probably not yet work with PHP 6. Installing on Unix pecl install xdebug On Unix, use: Documentation. Xdebug's built-in profiler allows you to find bottlenecks in your script and visualize those with an external tool such as KCacheGrind or WinCacheGrind.

Introduction Xdebug's Profiler is a powerful tool that gives you the ability to analyze your PHP code and determine bottlenecks or generally see which parts of your code are slow and could use a speed boost. The profiler in Xdebug 2 outputs profiling information in the form of a cachegrind compatible file. This allows you to use the excellent KCacheGrind tool (Linux/Windows, KDE) to analyse your profiling data. If you are on Linux you can install KCacheGrind with your favourite package manager; if you are on Windows you can get precompiled binaries of KCacheGrind at SourceForge.

Users of Windows can also use WinCacheGrind, the functionality is different from KCacheGrind so the section that documents the use of KCacheGrind on this page doesn't apply to this program. Starting The Profiler Analysing Profiles Related Settings Related Functions. Documentation. This section describes on how to install Xdebug. Precompiled Windows Modules There are a few precompiled modules for Windows, they are all for the non-debug version of PHP.

You can get those at the download page. Follow these instructions to get Xdebug installed. PECL Installation As of Xdebug 0.9.0 you can install Xdebug through PEAR/PECL. Installing with PEAR/PECL is as easy as: # pecl install xdebug but you still need to add the correct line to your php.ini: (don't forget to change the path and filename to the correct one — but make sure you use the full path) zend_extension="/usr/local/php/modules/xdebug.so" Note: You should ignore any prompts to add "extension=xdebug.so" to php.ini — this will cause problems. Installation From Source You can download the source of the latest stable release 2.2.5. Git clone This will checkout the latest development version which is currently 2.2.5. Compiling You compile Xdebug separately from the rest of PHP. Compatibility. Xdebug: Documentation. Xdebug.auto_trace Type: boolean, Default value: 0 When this setting is set to on, the tracing of function calls will be enabled just before the script is run.

This makes it possible to trace code in the auto_prepend_file. xdebug.cli_color Type: integer, Default value: 0, Introduced in Xdebug > 2.2 If this setting is 1, Xdebug will color var_dumps and stack traces output when in CLI mode and when the output is a tty. If the setting is 2, then Xdebug will always color var_dumps and stack trace, no matter whether it's connected to a tty or whether ANSICON is installed.

See this article for some more information. xdebug.collect_assignments Type: boolean, Default value: 0, Introduced in Xdebug > 2.1 This setting, defaulting to 0, controls whether Xdebug should add variable assignments to function traces. xdebug.collect_includes Type: boolean, Default value: 1 xdebug.collect_params Type: integer, Default value: 0 This setting can have four different values. Xdebug.collect_return xdebug.collect_vars req jit. Xdebug: Documentation. Documentation. Documentation. Xdebug provides an interface for debugger clients that interact with running PHP scripts.

This section explains how to set-up PHP and Xdebug to allow this, and introduces a few clients. Introduction Xdebug's (remote) debugger allows you to examine data structure, interactively walk through your and debug your code. There are two different protocols to communicate with the debugger: the old GDB-like command protocol (GDB) which is implemented in Xdebug 1.3 and 2; and the DBGp protocol which is implemented in Xdebug 2. Clients Xdebug 2 is bundled with a simple command line client for the DBGp protocol. A simple command line client for the GDB protocol is bundled with Xdebug 1.3.

Starting The Debugger In order to enable Xdebug's debugger you need to make some configuration settings in php.ini. After made all those settings Xdebug will still not start a debugging session automatically when a script is run. After a connection is made the output of the debug server is shown: Connect <? Req jit. Documentation. XDEBUG EXTENSION FOR PHP | DOCUMENTATION » The full documentation » Installation This section describes on how to install Xdebug. » Basic Features Xdebug's basic functions include the display of stack traces on error conditions, maximum nesting level protection and time tracking. » Variable Display Features Xdebug replaces PHP's var_dump() function for displaying variables. » Stack Traces When Xdebug is activated it will show a stack trace whenever PHP decides to show a notice, warning, error etc. » Function Traces Xdebug allows you to log all function calls, including parameters and return values to a file in different formats. » Code Coverage Analysis Code coverage tells you which lines of script (or set of scripts) have been executed during a request. » Profiling PHP Scripts Xdebug's built-in profiler allows you to find bottlenecks in your script and visualize those with an external tool such as KCacheGrind or WinCacheGrind. » Remote Debugging Frequently Asked Questions.