学习 PHP 断点调试

1、安装Xdebug

1
2
3
4
5
6
7
wgethttp://xdebug.org/files/xdebug-2.2.3.tgz
tarxzvfxdebug-2.2.3.tgz
cdxdebug-2.2.3
phpize
./configure
make
sudomakeinstall

2、启用xdebug:

在php.ini中加入如下一行(我的是mac) :

1
zend_extension="/usr/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"

参考http://netbeans.org/kb/docs/php/debugging_zh_CN.html

3、开启php.ini 中的调试功能

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
;xdebug.auto_trace
;Type:boolean,Defaultvalue:0
;Whenthissettingissettoon,thetracingoffunctioncallswillbeenabledjustbeforethe
;scriptisrun.Thismakesitpossibletotracecodeintheauto_prepend_file.
xdebug.auto_trace=0
;xdebug.collect_includes
;Type:boolean,Defaultvalue:1
;Thissetting,defaultingtoOn,controlswhetherXdebugshouldwritethefilenameusedininclude
;(),include_once(),require()orrequire_once()tothetracefiles.
xdebug.collect_includes=1
;xdebug.collect_params
;Type:integer,Defaultvalue:0
;
;Thissetting,defaultingto0,controlswhetherXdebugshouldcollecttheparameterspassedto
;functionswhenafunctioncallisrecordedineitherthefunctiontraceorthestacktrace.
xdebug.collect_params=0
;xdebug.collect_return
;Type:boolean,Defaultvalue:0
;Thissetting,defaultingtoOff,controlswhetherXdebugshouldwritethereturnvalueoffunction
;callstothetracefiles.
xdebug.collect_return=0
;xdebug.collect_vars
;Type:boolean,Defaultvalue:Off
;ThissettingtellsXdebugtogatherinformationaboutwhichvariablesareusedinacertainscope.
;ThisanalysiscanbequiteslowasXdebughastoreverseengineerPHP'sopcodearrays.Thissetting
;willnotrecordwhichvaluesthedifferentvariableshave,forthatusexdebug.collect_params.This
;settingneedstobeenabledonlyifyouwishtousexdebug_get_declared_vars().
xdebug.collect_vars="Off"
;xdebug.default_enable
;Type:boolean,Defaultvalue:On
;IfthissettingisOnthenstacktraceswillbeshownbydefaultonanerrorevent.Youcandisable
;showingstacktracesfromyourcodewithxdebug_disable().Asthisisoneofthebasicfunctionsof
;Xdebug,itisadvisabletoleavethissettingsetto'On'.
xdebug.default_enable="On"
;xdebug.dump.*
;Type:string,Defaultvalue:Empty
;*=COOKIE,FILES,GET,POST,REQUEST,SERVER,SESSION.Thesesevensettingscontrolwhichdata
;fromthesuperglobalsisshownwhenanerrorsituationoccurs.Eachphp.inisettingcanconsistof
;acommaseperatedlistofvariablesfromthissuperglobaltodump,butmakesureyoudonotadd
;spacesinthissetting.InordertodumptheREMOTE_ADDRandtheREQUEST_METHODwhenanerror
;occurs,addthissetting:
;
;xdebug.dump.SERVER=REMOTE_ADDR,REQUEST_METHOD
;xdebug.dump.SERVER=REMOTE_ADDR,REQUEST_METHOD
;xdebug.dump.COOKIE=""
;xdebug.dump.FILES=""
;xdebug.dump.GET=""
;xdebug.dump.POST=""
;xdebug.dump.REQUEST=""
;xdebug.dump.SERVER=""
;xdebug.dump.SESSION=""
;xdebug.dump_globals
;Type:boolean,Defaultvalue:1
;Controlswhetherthevaluesofthesuperglobalsasdefinedbythexdebug.dump.*settingswhouldbe
;shownornot.
xdebug.dump_globals=1
;xdebug.dump_once
;Type:boolean,Defaultvalue:1
;Controlswhetherthevaluesofthesuperglobalsshouldbedumpedonallerrorsituations(setto
;Off)oronlyonthefirst(settoOn).
xdebug.dump_once=1
;xdebug.dump_undefined
;Type:boolean,Defaultvalue:0
;IfyouwanttodumpundefinedvaluesfromthesuperglobalsyoushouldsetthissettingtoOn,
;otherwiseleaveitsettoOff.
xdebug.dump_undefined=0
;xdebug.extended_info
;Type:integer,Defaultvalue:1
;ControlswhetherXdebugshouldenforce'extended_info'modeforthePHPparser;thisallowsXdebug
;todofile/linebreakpointswiththeremotedebugger.Whentracingorprofilingscriptsyou
;generallywanttoturnoffthisoptionasPHP'sgeneratedoparrayswillincreasewithaboutathird
;ofthesizeslowingdownyourscripts.Thissettingcannotbesetinyourscriptswithini_set(),
;butonlyinphp.ini.
xdebug.extended_info=1
;xdebug.file_link_format
;Type:string,Defaultvalue:*emptystring*,IntroducedinXdebug2.1
;
;Thissettingdeterminestheformatofthelinksthataremadeinthedisplayofstacktraceswhere
;filenamesareused.ThisallowsIDEstosetupalink-protocolthatmakesitpossibletogo
;directlytoalineandfilebyclickingonthefilenamesthatXdebugshowsinstacktraces.
;xdebug.file_link_format=""
;xdebug.idekey
;Type:string,Defaultvalue:*complex*
;ControlswhichIDEKeyXdebugshouldpassontotheDBGpdebuggerhandler.Thedefaultisbasedon
;environmentsettings.FirsttheenvironmentsettingDBGP_IDEKEYisconsulted,thenUSERandaslast
;USERNAME.Thedefaultissettothefirstenvironmentvariablethatisfound.Ifnonecouldbe
;foundthesettinghasasdefault''.
;xdebug.idekey=""
;xdebug.manual_url
;Type:string,Defaultvalue:http://www.php.net
;Thisisthebaseurlforthelinksfromthefunctiontracesanderrormessagetothemanualpages
;ofthefunctionfromthemessage.Itisadvisabletosetthissettingtousetheclosestmirror.
;xdebug.manual_url="http://www.php.net"
;xdebug.max_nesting_level
;Type:integer,Defaultvalue:100
;Controlstheprotectionmechanismforinfiniterecursionprotection.Thevalueofthissettingis
;themaximumlevelofnestedfunctionsthatareallowedbeforethescriptwillbeaborted.
;xdebug.max_nesting_level=100
;xdebug.overload_var_dump
;Type:boolean,Defaultvalue:1,IntroducedinXdebug2.1
;BydefaultXdebugoverloadsvar_dump()withitsownimprovedversionfordisplayingvariableswhen
;thehtml_errorsphp.inisettingissetto1.Incaseyoudonotwantthat,youcansetthissetting
;to0,butcheckfirstifit'snotsmartertoturnoffhtml_errors.
;xdebug.overload_var_dump=1
;xdebug.profiler_append
;Type:integer,Defaultvalue:0
;Whenthissettingissetto1,profilerfileswillnotbeoverwrittenwhenanewrequestwouldmap
;tothesamefile(depndingonthexdebug.profiler_output_namesetting.Insteadthefilewillbe
;appendedtowiththenewprofile.
xdebug.profiler_append=0
;xdebug.profiler_enable
;Type:integer,Defaultvalue:0
;EnablesXdebug'sprofilerwhichcreatesfilesintheprofileoutputdirectory.Thosefilescanbe
;readbyKCacheGrindtovisualizeyourdata.Thissettingcannotbesetinyourscriptwithini_set
;().
xdebug.profiler_enable=0
;xdebug.profiler_enable_trigger
;Type:integer,Defaultvalue:0
;Whenthissettingissetto1,youcantriggerthegenerationofprofilerfilesbyusingthe
;XDEBUG_PROFILEGET/POSTparameter.Thiswillthenwritetheprofilerdatatodefineddirectory.
xdebug.profiler_enable_trigger=0
;xdebug.profiler_output_dir
;Type:string,Defaultvalue:/tmp
;Thedirectorywheretheprofileroutputwillbewrittento,makesurethattheuserwhothePHP
;willberunningashaswritepermissionstothatdirectory.Thissettingcannotbesetinyour
;scriptwithini_set().
xdebug.profiler_output_dir="D:/ProgramFiles/XAMPP/xampp/tmp"
;xdebug.profiler_output_name
;Type:string,Defaultvalue:cachegrind.out.%p
;
;Thissettingdeterminesthenameofthefilethatisusedtodumptracesinto.Thesetting
;specifiestheformatwithformatspecifiers,verysimilartosprintf()andstrftime().Thereare
;severalformatspecifiersthatcanbeusedtoformatthefilename.
;
;Seethexdebug.trace_output_namedocumentationforthesupportedspecifiers.
xdebug.profiler_output_name="xdebug_profile.%p"
;xdebug.remote_autostart
;Type:boolean,Defaultvalue:0
;NormallyyouneedtouseaspecificHTTPGET/POSTvariabletostartremotedebugging(seeRemote
;Debugging).Whenthissettingissetto'On'Xdebugwillalwaysattempttostartaremotedebugging
;sessionandtrytoconnecttoaclient,eveniftheGET/POST/COOKIEvariablewasnotpresent.
xdebug.remote_autostart=0
;xdebug.remote_enable
;Type:boolean,Defaultvalue:0
;ThisswitchcontrolswhetherXdebugshouldtrytocontactadebugclientwhichislisteningonthe
;hostandportassetwiththesettingsxdebug.remote_hostandxdebug.remote_port.Ifaconnection
;cannotbeestablishedthescriptwilljustcontinueasifthissettingwasOff.
xdebug.remote_enable=1
;xdebug.remote_handler
;Type:string,Defaultvalue:dbgp
;Canbeeither'php3'whichselectstheoldPHP3styledebuggeroutput,'gdb'whichenablestheGDB
;likedebuggerinterfaceor'dbgp'-thebrandnewdebuggerprotocol.TheDBGpprotocolismore
;widelysupportedbyclients.SeemoreinformationintheintroductionforRemoteDebugging.
xdebug.remote_handler="dbgp"
;xdebug.remote_host
;Type:string,Defaultvalue:localhost
;Selectsthehostwherethedebugclientisrunning,youcaneitheruseahostnameoranIP
;address.
xdebug.remote_host="localhost"
;xdebug.remote_log
;Type:string,Defaultvalue:none
;Ifsettoavalue,itisusedasfilenametoafiletowhichallremotedebuggercommunicationsare
;logged.Thefileisalwaysopenedinappend-mode,andwillthereforenotbeoverwrittenbydefault.
;Thereisnoconcurrencyprotectionavailable.
;xdebug.remote_log="none"
;xdebug.remote_mode
;Type:string,Defaultvalue:req
;
;Selectswhenadebugconnectionisinitiated.Thissettingcanhavetwodifferentvalues:
;
;req
;Xdebugwilltrytoconnecttothedebugclientassoonasthescriptstarts.
;jit
;Xdebugwillonlytrytoconnecttothedebugclientassoonasanerrorconditionoccurs.
;xdebug.remote_mode="req"
;xdebug.remote_port
;Type:integer,Defaultvalue:9000
;TheporttowhichXdebugtriestoconnectontheremotehost.Port9000isthedefaultforboththe
;clientandthebundleddebugclient.Asmanyclientsusethisportnumber,itisbesttoleavethis
;settingunchanged.
xdebug.remote_port=9000
;xdebug.show_exception_trace
;Type:integer,Defaultvalue:0
;Whenthissettingissetto1,Xdebugwillshowastacktracewheneveranexceptionisraised-
;evenifthisexceptionisactuallycaught.
;xdebug.show_exception_trace=0
;xdebug.show_local_vars
;Type:integer,Defaultvalue:0
;Whenthissettingissettosomething!=0Xdebug'sgeneratedstackdumpsinerrorsituationswill
;alsoshowallvariablesinthetop-mostscope.Bewarethatthismightgeneratealotof
;information,andisthereforeturnedoffbydefault.
;xdebug.show_local_vars=0
;xdebug.show_mem_delta
;Type:integer,Defaultvalue:0
;Whenthissettingissettosomething!=0Xdebug'shuman-readablegeneratedtracefileswillshow
;thedifferenceinmemoryusagebetweenfunctioncalls.IfXdebugisconfiguredtogenerate
;computer-readabletracefilesthentheywillalwaysshowthisinformation.
;xdebug.show_mem_delta=0
;xdebug.trace_format
;Type:integer,Defaultvalue:0
;Theformatofthetracefile.
;
;SeetheintroductionofFunctionTracesforafewexamples.
;xdebug.trace_format=0
;xdebug.trace_options
;Type:integer,Defaultvalue:0
;Whensetto'1'thetracefileswillbeappendedto,insteadofbeingoverwritteninsubsequent
;requests.
;xdebug.trace_options=0
;xdebug.trace_output_dir
;Type:string,Defaultvalue:/tmp
;Thedirectorywherethetracingfileswillbewrittento,makesurethattheuserwhothePHPwill
;berunningashaswritepermissionstothatdirectory.
;xdebug.trace_output_name
xdebug.trace_output_dir="D:/ProgramFiles/XAMPP/xampp/tmp"
;Type:string,Defaultvalue:trace.%c
;
;Thissettingdeterminesthenameofthefilethatisusedtodumptracesinto.Thesetting
;specifiestheformatwithformatspecifiers,verysimilartosprintf()andstrftime().Thereare
;severalformatspecifiersthatcanbeusedtoformatthefilename.The'.xt'extensionisalways
;addedautomatically.
;xdebug.trace_output_name="trace.%c"
;xdebug.var_display_max_children
;Type:integer,Defaultvalue:128
;Controlstheamountofarraychildrenandobject'spropertiesareshownwhenvariablesare
;displayedwitheitherxdebug_var_dump(),xdebug.show_local_varsorthroughFunctionTraces.This
;settingdoesnothaveanyinfluenceonthenumberofchildrenthatissendtotheclientthrough
;theRemoteDebuggingfeature.
;xdebug.var_display_max_children=128
;xdebug.var_display_max_data
;Type:integer,Defaultvalue:512
;Controlsthemaximumstringlengththatisshownwhenvariablesaredisplayedwitheither
;xdebug_var_dump(),xdebug.show_local_varsorthroughFunctionTraces.Thissettingdoesnothave
;anyinfluenceontheamountofdatathatissendtotheclientthroughtheRemoteDebugging
;feature.
;xdebug.var_display_max_data=512
;xdebug.var_display_max_depth
;Type:integer,Defaultvalue:3
;Controlshowmanynestedlevelsofarrayelementsandobjectpropertiesarewhenvariablesare
;displayedwitheitherxdebug_var_dump(),xdebug.show_local_varsorthroughFunctionTraces.This
;settingdoesnothaveanyinfluenceonthedepthofchildrenthatissendtotheclientthroughthe
;RemoteDebuggingfeature.
;xdebug.var_display_max_depth=3

我的是使用的是phpStorm

我的简单的配置为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
xdebug.auto_trace=on
xdebug.idekey="PHPSTORM"
xdebug.remote_host=127.0.0.1
xdebug.remote_enable=on
xdebug.remote_port=9000
xdebug.remote_handler="dbgp"
xdebug.auto_trace=1
xdebug.collect_includes=1
xdebug.collect_params=1
xdebug.collect_return=1
xdebug.default_enable=1
xdebug.collect_assignments=1
xdebug.collect_vars=1
xdebug.remote_autostart=1
xdebug.remote_connect_back=1
xdebug.show_local_vars=1
xdebug.show_exception_trace=0

注意:xdebug输出没样式了

解决办法就是

将html_errors改为On