php:xdebug
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
php:xdebug [2014/06/05 05:59] – [Config tracing of function calls] admin | php:xdebug [2022/10/29 16:15] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Debug PHP with xdebug ===== | ||
+ | Refer: http:// | ||
+ | ===== xdebug architecture ===== | ||
+ | ==== PHP Cli Debugging ===== | ||
+ | {{: | ||
+ | The PHP extension php_xdebug.dll seamlessly installs code to provide interpreter control and communication between a client (Notepad++ with DBGp plugin installed in the IDE) and the PHP interpreter over port 9000. Effectively php_xdebug.dll includes a mini server to provide communication with a client.\\ | ||
+ | Sequence of events | ||
+ | * Step A) Run Notepad++. | ||
+ | * Step B) Start Notepad++' | ||
+ | * (listens on port 9000) | ||
+ | * Step C) Run script from Notepad++ (Executes PHP interpreter). | ||
+ | * Step D) Interpreter loads configuration file and loads extensions (php_xdebug.dll) | ||
+ | * Step E) XDebug establishes contact with client. | ||
+ | * Step F) Script is loaded and run. | ||
+ | * Step G) Script execution (debugging) is controlled by client. | ||
+ | Notes: | ||
+ | * Note 1: Debugging is initiated as soon as the interpreter loads XDebug. | ||
+ | * Note 2: If the script is initiated from an external source (for example, a batch file), XDebug determines if the script (F) is displayed in Notepad++. If not, it is downloaded. | ||
+ | |||
+ | * Note 3: If XDebug starts debugging a new page, that page is downloaded if not already displayed in Notepad++. | ||
+ | ==== Web page Debugging ===== | ||
+ | {{: | ||
+ | The second server is created using a PHP extension (php_xdebug.dll). It seamlessly installs code to provide communication between Apache and a client (Notepad++ with DBGpplugin installed) over port 9000. In addition, code is installed to monitor browser requests arriving on the standard Apache port 80.\\ | ||
+ | Sequence of events(Assumes Uniform Server running (Apache server running)) | ||
+ | * Step A) Start Notepad++. | ||
+ | * Step B) Notepad++' | ||
+ | * Step C) In a browser, enter address of PHP page to be debugged. | ||
+ | * Step D) Browser requests this page from Apache server over port 80 | ||
+ | * Step E) Apache runs the PHP interpreter | ||
+ | * Step F) PHP interpreter runs its extensions including the XDebug module. | ||
+ | |||
+ | * Step G) XDebug module starts remote debugging. | ||
+ | * Step H) XDebug connects to debugging client over port 9000 | ||
+ | |||
+ | * Step I) User uses client for debugging. Commands and data are sent over port 9000 | ||
+ | * Step J) Client can instruct XDebug to execute one or more php statements. Your PHP code is executed; this may output data over http Port (80) to web browser. | ||
+ | |||
+ | * Step K) When all your PHP code has been executed, XDdebug disconnects from client. | ||
+ | * Step L) Followed by Apache closing connection to browser. | ||
+ | ===== Config and run xdebug on windows ===== | ||
+ | ==== Check and download xdebug dll ==== | ||
+ | *Step1: Run http:// | ||
+ | PHP Version 5.3.13 | ||
+ | Compiler MSVC9 (Visual C++ 2008) | ||
+ | Architecture x86 | ||
+ | Zend Extension Build API220090626, | ||
+ | </ | ||
+ | * Step2: Base on above information, | ||
+ | * PHP 5.3 VC9 TS (64 bit): | ||
+ | * PHP 5.3 VC9 TS (32 bit): | ||
+ | ==== config and check ==== | ||
+ | === config === | ||
+ | [php.ini] | ||
+ | < | ||
+ | [Xdebug] | ||
+ | zend_extension=" | ||
+ | xdebug.remote_enable=on | ||
+ | xdebug.remote_handler=dbgp | ||
+ | xdebug.remote_host=localhost | ||
+ | xdebug.remote_port=9000 | ||
+ | </ | ||
+ | === check === | ||
+ | * Check with PHP cli:< | ||
+ | " | ||
+ | </ | ||
+ | [Zend Modules] | ||
+ | Xdebug | ||
+ | </ | ||
+ | * check with phpinfo.php: | ||
+ | {{: | ||
+ | === Config | ||
+ | Normal config: | ||
+ | < | ||
+ | xdebug.auto_trace=On | ||
+ | xdebug.trace_output_dir=c: | ||
+ | </ | ||
+ | Custom config:\\ | ||
+ | **xdebug.collect_assignments**: | ||
+ | ===== xdebug-trace-gui ===== | ||
+ | ==== web config ==== | ||
+ | * update php.ini for xdebug:< | ||
+ | [Xdebug] | ||
+ | zend_extension=" | ||
+ | xdebug.auto_trace=On | ||
+ | xdebug.trace_format=1 | ||
+ | xdebug.trace_output_dir=c: | ||
+ | xdebug.show_mem_delta=On | ||
+ | xdebug.var_display_max_data=128 | ||
+ | xdebug.collect_params=4 | ||
+ | xdebug.collect_return=On | ||
+ | xdebug.trace_options=1 | ||
+ | xdebug.trace_output_name= %H-%R-%r.trace | ||
+ | xdebug.profiler_output_name = %s.%t.profile | ||
+ | xdebug.profiler_output_dir=c: | ||
+ | </ | ||
+ | * config virtualhost for xdebug in apache config:< | ||
+ | < | ||
+ | DocumentRoot " | ||
+ | ServerName xdebug.babies.vn | ||
+ | ServerAlias xdebug.babies.vn | ||
+ | DirectoryIndex index.php index.html index.htm | ||
+ | < | ||
+ | Options Indexes FollowSymLinks MultiViews | ||
+ | AllowOverride all | ||
+ | Order Deny,Allow | ||
+ | php_value ' | ||
+ | php_value default_charset " | ||
+ | Allow from all | ||
+ | </ | ||
+ | ErrorLog " | ||
+ | CustomLog " | ||
+ | </ | ||
+ | </ | ||
+ | ==== Use xdebug gui ==== | ||
+ | using http:// | ||
+ | * search follow instruction | ||
+ | {{: | ||
+ | {{: | ||
+ | * search follow script file | ||
+ | {{: | ||
+ | {{: | ||
+ | ===== log structure in xdebug ===== | ||
+ | ==== drupal example code run ==== | ||
+ | * index.php{{: | ||
+ | * bootstrap.php{{: | ||
+ | ==== parser xdebug log of drupal ==== | ||
+ | * Log< | ||
+ | Version: 2.2.5 | ||
+ | File format: 2 | ||
+ | TRACE START [2014-06-07 07:14:44] | ||
+ | 1 0 0 0.000966 336000 {main} 1 D: | ||
+ | 2 1 0 0.001141 336088 getcwd 0 D: | ||
+ | 2 1 1 0.001283 336120 | ||
+ | 2 2 0 0.001346 336152 define 0 D: | ||
+ | 2 2 1 0.001511 336184 | ||
+ | 2 3 0 0.008206 983872 require_once 1 D: | ||
+ | 3 4 0 0.008360 984000 define 0 D: | ||
+ | 3 4 1 0.008518 984016 | ||
+ | 3 5 0 0.008633 984040 define 0 D: | ||
+ | 3 5 1 0.008774 984056 | ||
+ | 3 6 0 0.008816 984048 define 0 D: | ||
+ | 3 6 1 0.008953 984064 | ||
+ | 3 7 0 0.009020 984072 define 0 D: | ||
+ | 3 7 1 0.009107 984088 | ||
+ | 3 8 0 0.009131 984056 define 0 D: | ||
+ | 3 8 1 0.009209 984056 | ||
+ | 3 9 0 0.009232 984056 define 0 D: | ||
+ | 3 9 1 0.009309 984056 | ||
+ | 3 10 0 0.009332 984064 define 0 D: | ||
+ | 3 10 1 0.009409 984064 | ||
+ | 3 11 0 0.009432 984056 define 0 D: | ||
+ | 3 11 1 0.009509 984056 | ||
+ | 3 12 0 0.009531 984064 define 0 D: | ||
+ | 3 12 1 0.009613 984064 | ||
+ | 3 13 0 0.009635 984056 define 0 D: | ||
+ | 3 13 1 0.009712 984056 | ||
+ | 3 14 0 0.009734 984064 define 0 D: | ||
+ | 3 14 1 0.009810 984064 | ||
+ | 3 15 0 0.009832 984056 define 0 D: | ||
+ | 3 15 1 0.009908 984056 | ||
+ | 3 16 0 0.009930 984056 define 0 D: | ||
+ | 3 16 1 0.010006 984056 | ||
+ | 3 17 0 0.010027 984056 define 0 D: | ||
+ | 3 17 1 0.010104 984056 | ||
+ | 3 18 0 0.010125 984072 define 0 D: | ||
+ | 3 18 1 0.010202 984072 | ||
+ | 3 19 0 0.010224 984072 define 0 D: | ||
+ | 3 19 1 0.010300 984072 | ||
+ | 3 20 0 0.010322 984072 define 0 D: | ||
+ | 3 20 1 0.010399 984072 | ||
+ | 3 21 0 0.010420 984072 define 0 D: | ||
+ | 3 21 1 0.010497 984072 | ||
+ | 3 22 0 0.010520 984072 define 0 D: | ||
+ | 3 22 1 0.010602 984072 | ||
+ | 3 23 0 0.010625 984072 define 0 D: | ||
+ | 3 23 1 0.010704 984072 | ||
+ | 3 24 0 0.010726 984072 define 0 D: | ||
+ | 3 24 1 0.010804 984072 | ||
+ | 3 25 0 0.010827 984064 define 0 D: | ||
+ | 3 25 1 0.010905 984064 | ||
+ | 3 26 0 0.010927 984064 define 0 D: | ||
+ | 3 26 1 0.011004 984064 | ||
+ | </ | ||
+ | * Description parameters in xdebug log{{: | ||
+ | ==== Get full log of 1 function with sub-functions ==== | ||
+ | * For example function seq: 4599< | ||
+ | Line 9548: | ||
+ | </ | ||
+ | * We will get the end of function by search the line end of function:< | ||
+ | Line 15997: | ||
+ | </ |