Xdebug waa qalab wax-ka-darid xoog leh oo PHP ah oo naga caawiya inaan falanqaynno oo aan tayaynno codsiyada PHP. Waxay taageertaa sifooyin ay ka mid yihiin sixid-tallaabo tallaabo-tallaabo, cabbiraadda waxqabadka iyo raad-raacista, taasoo ka dhigaysa cilad-raadinta mid aad u fudud oo bixisa fikrado wanaagsan oo ku saabsan koodka. Hoos waxaa ku yaal hage habayn yar oo loogu isticmaalo gudaha VSCode.
Ku rakib Xdebug
Tusaale ahaan, waxaan ku rakibnay Xdebug nidaamka Ubuntu ee hadda jira:
sudo apt-get install -y php8.4-xdebug
Ugu dambayntii, waxaanu abuurnay hage ku meel gaadh ah oo hadhow kaydinta xogta iyo raadinta xogta:
mkdir -p /tmp/xdebug
Habee Xdebug
Ka dib markii la rakibo, waxaan dejineynaa Xdebug. Si tan loo sameeyo, waan tafatireynaa so/php.ini:
vi /etc/php/8.4/fpm/conf.d/custom.ini
Waxa soo socda waa qaabeynta aasaasiga ah ee macquulka ah:
[xdebug]
; mode (see: https://xdebug.org/docs/all_settings#mode)
; reasonable default
xdebug.mode=debug,profile
; disabled
;xdebug.mode=off
; step debugging
;xdebug.mode=debug
; performance profiling (be aware of load/space)
;xdebug.mode=profile
; trace profiling (record args)
;xdebug.mode=trace
; starting mode
; always (not recommended)
;xdebug.start_with_request=yes
; only when specific get parameters / cookies are set
; (?XDEBUG_TRIGGER=1, ?XDEBUG_PROFILE=1, ?XDEBUG_TRACE=1, ?XDEBUG_SESSION=1)
; this is best in conjunction with Chrome extension "Xdebug helper"
xdebug.start_with_request=trigger
; folder for analyzing profile dumps
xdebug.output_dir="/tmp/xdebug"
; not needed, since it is already in /etc/php/8.4/fpm/conf.d/20-xdebug.ini
;zend_extension=xdebug.so
Kadib samaynta hagaajintan, waxaan dib u bilaabaynaa PHP-FPM si aan u isticmaalno isbeddelada:
sudo service php8.4-fpm restart
Habee VSCcode
Si loo isticmaalo Xdebug gudaha Visual Studio Code, laba kordhin iyo hagaajin qaabaynta ayaa loo baahan yahay. Waxaan rakibnaa tan:
- Qalabaynta PHP: loogu talagalay shaqeynta qaladka aasaasiga ah.
- Profiler PHP: Si loo falanqeeyo faylalka cachegrind
Ugu dambeyntii, waxaan ku abuureynaa galka qaabka launch.json ee gal .vscode ee mashruuca si loo falanqeeyo:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"ignore": ["**/vendor/**/*.php"]
}
]
}
Ku rakib Chrome Extension
Kordhinta caawiyaha Xdebug ayaa isku caddeeyey cilladaha dabacsan ee browserka. Tani waxay suurtogal ka dhigaysaa in la hawlgeliyo ama la joojiyo Xdebug kaliya marka loo baahdo. Waxa kale oo aad si fudud u beddeli kartaa qaabka khaladka (tusaale ahaan, si aad uga beddesho wax-ka-hortagga una beddelato astaanta):
Habee WordPress
Markaad isticmaalayso Xdebug deegaanka WordPress, waxaa laga yaabaa inay faa'iido u leedahay in la joojiyo khaladka gudaha shaqooyinka cron marka fadhiga wax-ka-hortagga ahi uu firfircoon yahay. Tani waxay fududaynaysaa codsiyada khaladka. Si tan loo sameeyo, ku dar xariiqda soo socota: wp-config.php
a:
// disable wp cron on xdebug sessions
if (function_exists('xdebug_is_debugger_active') && xdebug_is_debugger_active()) {
define('DISABLE_WP_CRON', true);
}
Qaabayntan waxa aanu ku haysanaa habayn awood leh oo noo ogolaanaysa in aanu si sax ah wax uga qabano dhibaatooyinka qallafsan ee adag. Haddii la helo dhiqlaha madax-adayga ama dhibaatooyinka waxqabadka hagaajinta - Xdebug kaliya kama dhigayso shaqada mid hufan, laakiin sidoo kale waxay keentaa tayada cusub ee horumarinta iyada oo la xakameynayo iyo caddaynta koodka.