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 Commands

Laravale commands #Check route list php artisan route:list #Check upload files links php artisan storage:link #Check database connected or not php artisan db #Make Request file php artisan make:request YourNameRequest #Make Controller #(In this statement you used -r -> resources and -m -> model. It will create CustomersController and Customers Model files) php artisan make:controller CustomersController -r -m Customers #Make Resource file php artisan make:resource CustomersResource #To check migration files status that those files are running or not with below commands php artisan migrate:status #To check if there is any pending migrate files to run #(also this command shows us the mysql query before running migration file) php artisan migrate --pretend #To make a database table (in this example Products name as taken) php artisan make:migration create_products_table #To create a Request file php artisan make:request StoreProductRequest php artisan make:request Up

Mysql columns creation in laravel

List of columns  $table->id(); // increment value $table->string('title')->comment('this is blog title'); $table->string('slug')->unique(); $table->text('short_desc'); $table->longText('description'); $table->boolean('is_published')->default(false); $table->integer('min_of_read')->nullable(true); $table->enum('status', ['Active', 'Inactive']); $table->float('discount'); $table->smallInteger('type_id'); $table->date('start_date')->nullable(); $table->timestamps(); $table->foreign('created_by')->references('id')->on('users'); // introducing foreign key $table->unsignedBigInteger('user_id'); //? $table->decimal('latitude', 9, 6)->nullable(true); // Let's say you want starting value from 1000 $table->id()->from(1000); // increment value start from 1000 ->nullabl

React Advanced JSX

 class vs className This lesson will cover more advanced JSX. You’ll learn some powerful tricks and some common errors to avoid. Grammar in JSX is mostly the same as in HTML, but there are subtle differences to watch out for. The most frequent of these involves the word class. In HTML, it’s common to use class as an attribute name: <h1 class = "big" > Title </h1> In JSX, you can’t use the word  class ! You have to use  className  instead: <h1 className = "big" > Title </h1> This is because JSX gets translated into JavaScript, and  class  is a reserved word in JavaScript. When JSX is  rendered , JSX  className  attributes are automatically rendered as  class  attributes. Self-Closing Tags Another common JSX error involves  self-closing tags . What’s a self-closing tag? Most HTML elements use two tags: an  opening tag  ( <div> ), and a  closing tag  ( </div> ). However, some HTML elements such as  <img>  and  <input>  u