php window系統 xdebug+phpstorm 本地斷點除錯使用教程
執行環境:
phpStorm 2017.2
PHP 7.1.5
Xdebug 2.6.1
php.ini新增xdebug模組
你需要仔細分析和選擇要下載的對應版本,否則無法除錯。由於非常容易出錯,建議採用下面這種簡單方法【注意:如果php版本與xdebug版本不匹配,雖然xdebug能安裝成功,但會出現phpstorm配置xdebug只有第一行斷點能觸發的問題,如出現這個問題請重新更換xdebug版本】:
首先獲取phpinfo()函式的資訊,如下圖
ctrl+A全選這個頁面的資訊,然後貼上到第一個圖片的頁面中。
不知道這個頁面如何出現的同學在你的php伺服器程式目錄下 建立一個phpinfo.php檔案,只需一行程式碼
<?php phpinfo(); ?>
瀏覽器中輸入 http://127.0.0.1/phpinfo.php 就出現上圖的頁面了。
然後,xdebug網站提供一個自動分析你係統對應的xdebug版本的頁面,網址是 https://xdebug.org/wizard.php,開啟把複製的內容輸入到網址的編輯框中,如下圖
把下載的dll檔案放到php的ext擴充套件目錄裡面,最後在php.ini上新增以下配置:
xdebug.idekey = PHPSTORM xdebug.auto_trace=1 xdebug.collect_params = 1 xdebug.collect_return = 1 xdebug.auto_trace = 1 xdebug.remote_enable = 1 xdebug.remote_host = localhost xdebug.remote_port = 9070 xdebug.remote_handler = dbgp
重啟apache 或者nginx檢測xdebug是否安裝成功。【特別提示:不管是Windows還是Linux安裝xdebug都需要以zend擴充套件的形式安裝,如果提示XDEBUG NOT LOADED AS ZEND EXTENSION即下圖所示介面則沒有正確安裝,需要重新修改配置檔案。】
phpstorm配置xdebug支援
開啟phpStorm,快捷鍵Clt+Alt+S開啟settings,配置debug
開啟phpStorm,快捷鍵Clt+Alt+S開啟settings,配置services
開啟phpStorm,快捷鍵Clt+Alt+S開啟settings,配置dbgp
開啟phpStorm,新增除錯配置
開啟phpStorm,斷點執行檢視效果。
附帶本例子除錯的php程式碼
//封裝方法,取餘 function kmod($x, $y) { //fmod() 函式返回除法的浮點數餘數 return intval(fmod(floatval($x), $y)); } //數字標識 $mark_num = 1111; //總數 $count = 15; echo rand(111,222222); $remainder_arr = []; if(is_numeric($mark_num)){ $y = $count/2; $init_num = 1; $step = 1; $auto_num = 1; while ($init_num <= 5) { if($step%2== 1){ $remainder = kmod($mark_num-$step,$y); }else{ $remainder = kmod($mark_num+$step,$y); } if(!in_array($remainder,$remainder_arr)){ $remainder_arr[] = $remainder; $init_num++; } if($auto_num >=100000){ //防止死迴圈 break; } $auto_num++; $step++; } } print_r($remainder_arr); echo 1;