Xdebug sisixhobo esinamandla se-PHP sokulungisa iimpazamo kunye nesixhobo sokwenza iprofayili esisinceda sihlalutye kwaye sisebenzise usetyenziso lwe-PHP. Ixhasa iimpawu ezifana nokulungiswa kwesinyathelo-nge-nyathelo, ukulinganisa ukusebenza kunye nokulandelwa kwe-stack, eyenza ukuxazulula iingxaki kube lula kakhulu kwaye unikeze ukuqonda okungcono kwikhowudi. Apha ngezantsi kukho isikhokelo esincinci sokucwangcisa ukusetyenziswa ngaphakathi kweVSCode.
Faka i-Xdebug
Njengomzekelo, sifaka i-Xdebug kwinkqubo ye-Ubuntu yangoku:
sudo apt-get install -y php8.4-xdebug
Okokugqibela, senza uvimba weefayili wexeshana wogcino lwamva lweprofayile kunye nokulanda idatha:
mkdir -p /tmp/xdebug
Qwalasela iXdebug
Emva kokufakela, siqwalasela iXdebug. Ukwenza oku, siyayihlela xh/php.ini:
vi /etc/php/8.4/fpm/conf.d/custom.ini
Oku kulandelayo luqwalaselo olusisiseko olunengqiqo:
[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
Emva kokwenza olu hlengahlengiso, siqala kwakhona i-PHP-FPM ukuze sisebenzise utshintsho:
sudo service php8.4-fpm restart
Qwalasela i-VSCCode
Ukusebenzisa i-Xdebug kwiKhowudi yeSitudiyo esiBonakalayo, izongezo ezibini kunye nolungelelwaniso lolungelelwaniso luyafuneka. Sifaka oku:
- PHP Debug: umsebenzi osisiseko wokulungisa iimpazamo.
- PHP Profiler: Ukuhlalutya iifayile ze-cachegrind.
Okokugqibela, senza ifayile yoqwalaselo.json kwifayile ye .vscode yeprojekthi eza kuhlalutywa.:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"ignore": ["**/vendor/**/*.php"]
}
]
}
Faka iChrome Extension
Ulwandiso lomncedisi we-Xdebug luzibonakalisile ngokwalo ngolungiso lweempazamo kwisikhangeli. Oku kwenza ukuba kwenzeke okanye ukuvala iXdebug kuphela xa kuyimfuneko. Ungayitshintsha ngokulula imo yedebug (umzekelo, ukuswitsha ukusuka kwidebugging ukuya kwiprofayile):
Cwangcisa iWordPress
Xa usebenzisa i-Xdebug kwindawo ye-WordPress, kunokuba luncedo ukukhubaza ukulungisa ingxaki ngaphakathi kwemisebenzi ye-cron xa iseshoni yolungiso lweempazamo isebenza. Oku kwenza izicelo zokulungisa zibe lula. Ukwenza oku, yongeza umgca olandelayo ku: 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);
}
Ngolu lungelelwaniso sinoseto olunamandla olusivumela ukuba sijongane neengxaki zokulungisa ingxaki ngokuchanekileyo. Nokuba ufumana iibugs ezinenkani okanye iingxaki zokulungisa kakuhle- Xdebug ayenzi nje umsebenzi usebenze ngakumbi, kodwa izisa umgangatho omtsha kuphuhliso ngolawulo kunye nokucaca ngaphezulu kwekhowudi.