PHP的远程多会话调试

巴扎黑
Release: 2023-03-16 11:50:02
Original
1418 people have browsed it

这篇文章主要给大家介绍了关于PHP远程多会话调试的相关资料,文中通过示例代码以及图片介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧。

一、背景介绍

本文主要给大家介绍了关于PHP远程多会话调试的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍:

解决什么问题:多个项目断点调试,www.mysite.com项目会调用api.mysite.com项目REST接口,在www.mysite.com项目下触发动作时,更方便的直接调试api.mysite.com项目中的接口。

适用什么场景:跨项目调试,远程调试,比简单的var_dump更方便易用。

二、远程调试配置

Nginx+PHP-fpm环境,配置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
Copy after login

注意:CLI环境的php与fpm的php是否使用的不同php.ini配置文件,需要配置fpm对应的php.ini

检查是否配置正确

将远程(fpm所在主机10.99.1.185)端口9000映射到本地端口9000:


ssh -CNg -R 9000:localhost:9000 [email protected]
Copy after login

本地安装openssh后可以直接使用ssh命令

在服务器可以看到9000端口被ssh占用

PHPSTORM也需要配置Xdebug,配置同时启用的调试会话为多个,端口9000,接受外部请求。

配置项目相关的path mapping,域名,端口

三、跨会话(项目)调试配置

跨项目调试的核心是把触发Xdebug调试的条件作为参数发送给api.mysite.com项目或者后续的其他项目。

www项目代码如下:

frontend.php


Copy after login

api项目代码如下:

backend.php


Name = "Maarten";

$person->Email = "[email protected]";

echo json_encode($person);
Copy after login

需要修改www项目,把xdebug所需要的触发远程调试的网络请求参数加上:


Copy after login

自有项目可以在通用的网络请求封装类中增加cookie参数:


curl_setopt($this->ch, CURLOPT_COOKIE, "XDEBUG_SESSION=XDEBUG");
Copy after login

四、调试流程

  • 确保调试参数已经转发给api接口

  • 增加同时可以调试的会话数量

  • 开启调试监听,开启服务端Xdebug

The above is the detailed content of PHP的远程多会话调试. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!