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

Data Types in Python

Data Types  In C# or Java, You need to declare a variable specify them integer, string, and decimal. But in Python no need to specify. We can declare variables like Example: C# or Java int age = 28; string Name = "Siddhu"; Example: Python age = 28 Name = "Siddhu" So, you don't need to declare variable types in python. This is an advantage in Python, But still have few Disadvantages too. Example: In my Python function def add_numbers(x,y): print(x+y) add_numbers(20,50) //Output: 70 add_numbers(20,"Something") //Error:"Traceback (most recent call last): File "C:/Users/siddhartha.e/PycharmProjects/siddhu-py/my1stpycode.py", line 8, in add_numbers(50,"Something") File "C:/Users/siddhartha.e/PycharmProjects/siddhu-py/my1stpycode.py", line 4, in add_numbers print(a + b) TypeError: unsupported operand type(s) for +: 'int' and 'str'" ...

Database and Migrations

Database and Migrations You can config Database in the .env file. By default, Laravel has MySQL configuration. For example, I configured my details DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=Laravel_tutorials DB_USERNAME=root DB_PASSWORD= So how it connects the database, In your root folder config/database.php file will read the .env file configuration. Migrations: Migrations are most likely a version control for your database. Advantages You can easily allow your team to modify database schema and share to everyone in the application No headache to add a new column in the database manually. This migration will help all teammates into one path. Now check with artisan command php artisan migrate php artisan migrate This command will create basic users,password_resets and migrations tables. Here migrations table will track of all migrates You can undo previous migration using rollback command php artisan ...

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', ...