Skip to main content

Debug the PHP Application with Xdebug, WinCacheGrind and Windows

The Xdebug extension encourages you to troubleshoot your content by giving a great deal of profitable investigate data.

Installing Xdebug for XAMPP with PHP 7.x

Basic Requirements


  1. XAMPP for Windows: https://www.apachefriends.org/download.html
  2. The VC14 builds require to have the Visual C++ Redistributable for Visual Studio 2015 x86 or x64 installed
  3. The VC15 builds require to have the Visual C++ Redistributable for Visual Studio 2017 x64 or x86 installed

Setup

Download Xdebug for:

  1. PHP 7.0.x: https://xdebug.org/files/php_xdebug-2.5.5-7.0-vc14.dll
  2. PHP 7.1.x: https://xdebug.org/files/php_xdebug-2.5.5-7.1-vc14.dll
  3. PHP 7.2.x: https://xdebug.org/files/php_xdebug-2.6.0-7.2-vc15.dll
  4. Copy the file php_xdebug-2.6.0-7.2-vc15.dll to C:\xampp\php\ext
  5. Open the file C:\xampp\php\php.ini with Notepad++
  6. Disable output buffering: output_buffering = Off
  7. Scroll down to the [XDebug] section (or create it) and copy this lines

 
[XDebug]
zend_extension = "c:\xampp\php\ext\php_xdebug-2.6.0-7.2-vc15.dll"
xdebug.remote_autostart = 1
xdebug.profiler_append = 0
xdebug.profiler_enable = 0
xdebug.profiler_enable_trigger = 0
xdebug.profiler_output_dir = "c:\xampp\tmp"
;xdebug.profiler_output_name = "cachegrind.out.%t-%s"
xdebug.remote_enable = 1
xdebug.remote_handler = "dbgp"
xdebug.remote_host = "127.0.0.1"
xdebug.remote_log = "c:\xampp\tmp\xdebug.txt"
xdebug.remote_port = 9000
xdebug.trace_output_dir = "c:\xampp\tmp"
;36000 = 10h
xdebug.remote_cookie_expire_time = 36000

     9. Restart the Apache (Stop/Start)

Now, if you run the phpinfo(); you can see the xdebug extension is enabled

phpinfo

By default Xdebug profile log name as cachegrind.out  You can add extra parameters to make dynamic. For myself, I added %t-%s which formats are

SpecifierMeaningExample FormatExample Filename
%ccrc32 of the current working directorycachegrind.out.%ccachegrind.out.1258863198.xt
%ppidcachegrind.out.%pcachegrind.out.5174.xt
%rrandom numbercachegrind.out.%rcachegrind.out.072db0.xt
%sscript name 2cachegrind.out.%scachegrind.out._home_httpd_html_test_xdebug_test_php
%ttimestamp (seconds)cachegrind.out.%tcachegrind.out.1179434742.xt
%utimestamp (microseconds)cachegrind.out.%ucachegrind.out.1179434749_642382.xt
%H$_SERVER['HTTP_HOST']cachegrind.out.%Hcachegrind.out.kossu.xt
%R$_SERVER['REQUEST_URI']cachegrind.out.%Rcachegrind.out._test_xdebug_test_php_var=1_var2=2.xt
%U$_SERVER['UNIQUE_ID'] 3cachegrind.out.%Ucachegrind.out.TRX4n38AAAEAAB9gBFkAAAAB.xt
%Ssession_id (from $_COOKIE if set)cachegrind.out.%Scachegrind.out.c70c1ec2375af58f74b390bbdd2a679d.xt
%%literal %cachegrind.out.%%cachegrind.out.%%.xt

Here %s is used for modifying only xdebug.profiler_output_name and not for xdebug.trace_output_name. 

And If you want to get the current profiling log file. you can call the function
xdebug_get_profiler_filename(), which returns the file name as a string


if you enable the xdebug.profiler_enable. it will run every single script. It will run all the time. So instead of that enable the xdebug.profiler_enable_trigger, the benefit of using profiler_enable_trigger you can enable and disable profiling by just pass the special GET or POST parameter XDEBUG_PROFILE to a PHP script. It will turn on profiling just for the one PHP script that receives the parameter. You need not set a value for XDEBUG_PROFILE, it is sufficient to append the parameter to the URL: yourUrl.php?XDEBUG_PROFILE.


Comments

Popular posts from this blog

Laravel form validations

 Laravel Validations: List of types "first_name" => 'required|alpha:ascii|min:3|max:100',// alpha:ascii (only accepts a-z) "middle_name" => 'string', "last_name" => 'required|string', "email" => 'required|email|unique:users,email', "password" => 'required|string|confirmed', "sex" => 'required|string', "phone_no" => 'required|string', "account_type" => 'required|string', "dob" => 'required|date_format:d-m-Y', // date with format "nationality" => 'required|string', "company" => 'required|string', "company_sector" => 'required|string', "company_address" => 'required|string' "bank_account_no" => 'required|min_digits:3|max_digits:5', "role" => 'required|in:admin,editor,viewer', ...

React Js Commands

React JS Commands and Useful purposes  To Install react app: npx create-react-app app-name To Install react app: npx create-react-app . To check npm version: npm --version Inside that directory, you can run several commands:   npm start     Starts the development server.   npm run build     Bundles the app into static files for production.   npm test     Starts the test runner.   npm run eject     Removes this tool and copies build dependencies, configuration files     and scripts into the app directory. If you do this, you can’t go back! node -v (To check node version) The latest recommended command to create a new React app is: npx create-react-app@latest my-app Replace my-app with your desired project name. This approach uses the latest version of Create React App and works if Node.js (version 14+) and npm (version 5.2+) are installed Modern Alternatives If you prefer a faster, lighter setup, many developers n...

Reactjs jsx

ReactJS JSX   React is a modular, scalable, flexible, and popular front-end framework. What is JSX? JSX is a syntax extension for JavaScript. It was written to be used with React. JSX code looks a lot like HTML. What does “syntax extension” mean? In this case, it means that JSX is not valid JavaScript. Web browsers can’t read it! If a JavaScript file contains JSX code, then that file will have to be compiled. This means that before the file reaches a web browser, a JSX compiler will translate any JSX into regular JavaScript. Codecademy’s servers already have a JSX compiler installed, so you don’t have to worry about that for now. Eventually we’ll walk through how to set up a JSX compiler on your personal computer. JSX is a syntax extension for JavaScript which allows us to treat HTML as expressions. const h1 = <h1>Hello world</h1>; They can be stored in variables, objects, arrays, and more! Here’s an example of several JSX elements being stored in an object: const ...