您好,登錄后才能下訂單哦!
這篇文章主要介紹PHP中遠(yuǎn)程多會話調(diào)試的示例分析,文中介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們一定要看完!
一、背景介紹
解決什么問題:多個項目斷點(diǎn)調(diào)試,www.mysite.com項目會調(diào)用api.mysite.com項目REST接口,在www.mysite.com項目下觸發(fā)動作時,更方便的直接調(diào)試api.mysite.com項目中的接口。
適用什么場景:跨項目調(diào)試,遠(yuǎn)程調(diào)試,比簡單的var_dump更方便易用。
二、遠(yuǎn)程調(diào)試配置
Nginx+PHP-fpm環(huán)境,配置php.ini拓展
[Xdebug] zend_extension = /usr/local/php56/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so xdebug.remote_enable=1 remote_handler=dbgp xdebug.remote_host=localhost xdebug.remote_port=9000 xdebug.idekey=XDEBUG
注意:CLI環(huán)境的php與fpm的php是否使用的不同php.ini配置文件,需要配置fpm對應(yīng)的php.ini
檢查是否配置正確
將遠(yuǎn)程(fpm所在主機(jī)10.99.1.185)端口9000映射到本地端口9000:
ssh -CNg -R 9000:localhost:9000 root@10.99.1.185
本地安裝openssh后可以直接使用ssh命令
在服務(wù)器可以看到9000端口被ssh占用
PHPSTORM也需要配置Xdebug,配置同時啟用的調(diào)試會話為多個,端口9000,接受外部請求。
配置項目相關(guān)的path mapping,域名,端口
三、跨會話(項目)調(diào)試配置
跨項目調(diào)試的核心是把觸發(fā)Xdebug調(diào)試的條件作為參數(shù)發(fā)送給api.mysite.com項目或者后續(xù)的其他項目。
www項目代碼如下:
frontend.php
<?php $personJson = file_get_contents('http://api.mysite.com/backend.php'); $person = json_decode($personJson); var_dump($person);
api項目代碼如下:
backend.php
<?php class Person { public $Name; public $Email; } $person = new Person(); $person->Name = "Maarten"; $person->Email = "maarten.balliauw@jetbrains.com"; echo json_encode($person);
需要修改www項目,把xdebug所需要的觸發(fā)遠(yuǎn)程調(diào)試的網(wǎng)絡(luò)請求參數(shù)加上:
<?php $debuggingQuerystring = ''; if (isset($_GET['XDEBUG_SESSION_START'])) { // xdebug $debuggingQuerystring = 'XDEBUG_SESSION_START=' . $_GET['XDEBUG_SESSION_START']; } if (isset($_COOKIE['XDEBUG_SESSION'])) { // xdebug (cookie) $debuggingQuerystring = 'XDEBUG_SESSION_START=PHPSTORM'; } if (isset($_GET['start_debug'])) { // zend debugger $debuggingQuerystring = 'start_debug=' . $_GET['start_debug']; } $personJson = file_get_contents('http://api.mysite.com/backend.php?' . $debuggingQuerystring); $person = json_decode($personJson); var_dump($person);
自有項目可以在通用的網(wǎng)絡(luò)請求封裝類中增加cookie參數(shù):
curl_setopt($this->ch, CURLOPT_COOKIE, "XDEBUG_SESSION=XDEBUG");
四、調(diào)試流程
確保調(diào)試參數(shù)已經(jīng)轉(zhuǎn)發(fā)給api接口
增加同時可以調(diào)試的會話數(shù)量
開啟調(diào)試監(jiān)聽,開啟服務(wù)端Xdebug
以上是“PHP中遠(yuǎn)程多會話調(diào)試的示例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。