Upgrade to Pro — share decks privately, control downloads, hide ads and more …

xdebug remote debugging

oscar.lee
November 05, 2014

xdebug remote debugging

oscar.lee

November 05, 2014
Tweet

More Decks by oscar.lee

Other Decks in Technology

Transcript

  1. 環境 Remote centos + nginx + php + Xdebug Local

    SublimeText + SublimeTextXdebug Browser (chrome) ! ! Xdebug Helper
  2. Remote 安裝Xdebug yum install php-devel yum install php-pear yum install

    gcc gcc-c++ autoconf automake pecl install Xdebug
  3. Remote 設定Xdebug locate php.ini //尋找php.ini位置 vi /etc/php.ini ! //加⼊入xdebug.so 路徑

    zend_extension=/usr/lib64/php/modules/xdebug.so ! [xdebug] xdebug.remote_port=9000 xdebug.remote_enable=1 xdebug.remote_connect_back=1 xdebug.remote_handler=dbgp xdebug.remote_host=127.0.0.1 xdebug.remote_autostart=1 xdebug.profiler_enable=1
  4. Remote設定nginx vi /etc/nginx/sites-available/xxxx.com location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index

    index.php; include /etc/nginx/fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root/ $fastcgi_script_name; fastcgi_param APPLICATION_ENV development; } ! vi /etc/php-fpm.d/www.conf [www] listen = 127.0.0.1:9000 ! 重起⽣生效 service php-fpm restart service nginx restart
  5. Local SublimeTextXdebug設定 在專案根⺫⽬目錄下新增xdebug.sublime-project { "folders": [ { "follow_symlinks": true, "path":

    "." } ], "settings": { "xdebug": { "path_mapping": { “/var/www/html/xxxx" : “~/wwwroot/project/xxxx", }, "url": “http://www.hiiir.com/api/v1”, "super_globals": true, "close_on_stop": true } } }
  6. 功能簡介 Start/Stop debugging session ( 啟動/關閉 Xdebug ) add/remove breakpoint

    ( 斷點,執⾏行到此會停住 ) Set watch expression ( 建⽴立觀察 ) Step over ( 遇到函式呼叫時,確定該函式不會有問題時使⽤用 ) Step into ( 遇到函式呼叫時跳進該函式 ) Step out ( 在函式中確認後⾯面程式無誤,跳⾄至上⼀一層 ) Session Evaluate ( 等同eval($code) )
  7. 視窗簡介 • Xdebug Context ( 觀察⺫⽬目前所有變數狀態 ) • Xdebug Watch

    ( 觀察某變數,歷程變化狀態 ) • Xdebug Stack ( 執⾏行 檔案⾏行⾛走路徑 ) • Xdebug Breakpoint ( 斷點⾏行數 )
  8. 測試程式 <?php ! $x = 1; $y = 2; !

    if ($x + $y == 2) { switch ($z) { case 'cat': echo 'meow '; case 'dog': echo 'Wang '; default: break; } } else { echo 'end'; } ⺫⽬目標: 輸出meow wang ! ! 1. 改變 $x = 0 結果 $x + $y = 2 ! 2. 新增 $z = ‘cat’; 結果 echo ‘meow’; ! 3.改變 $z = ‘dog’; 結果 echo ‘Wang’;
  9. > session evaluate $y = ‘cat’; > step into >

    session evaluate $y = ‘dog’; > Run ! switch ($y) { case 'cat': echo 'meow '; case 'dog': echo 'Wang '; default: break; } Run
  10. Q&A