Home  >  Article  >  Backend Development  >  Detailed graphic explanation of how to debug visual studio code in PHP

Detailed graphic explanation of how to debug visual studio code in PHP

黄舟
黄舟Original
2017-09-16 09:26:171837browse

本篇文章主要介绍了visual studio code 调试php方法(图文详解),具有一定的参考价值,有兴趣的可以了解一下

简介

php是动态语言没有调试器的话排错起来很是麻烦。vscode可以说是程序员的福音,启动速度快,插件越来越多,跨平台。现在说一下vscode上调试php文件

所需文件

  • xampp 集成服务器

  • vscode

  • Xdebug

  • php-debug 插件

1: 在vscode中按 F1, 输入ext install php-debug 安装调试插件

2:去 https://xdebug.org/download.php下载php对应版本的插件,php版本可以在xampp中的readme看到,下载这个PHP 5.6 VC11 TS (32 bit) 把dll文件拷贝到php目录

Detailed graphic explanation of how to debug visual studio code in PHP

3:打开php目录下的php.ini ,添加几行配置,xdebug的路径按实际情况配置,配置完成后重启apache服务器


zend_extension=C:\xampp\php\ext\php_xdebug-2.4.1-5.6-vc11.dll
[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1

4:第一次安装vs会提示这个,需要配置下php.exe的路径,在用户设置里添加以下项


"php.validate.executablePath": "C:\\xampp\\php\\php.exe"

Detailed graphic explanation of how to debug visual studio code in PHP

5:在vscode中的php文件打一断点,点Listen for XDebug 项目的运行,配置不用更改,默认就可以
Detailed graphic explanation of how to debug visual studio code in PHP

6:运行后跳出这些按键

Detailed graphic explanation of how to debug visual studio code in PHP

7:直接在浏览器中打开要调试的php(不是文件路径而是服务器的地址(http://127.0.0.1/test.php)),vscode就会命中到打断点的地方

Detailed graphic explanation of how to debug visual studio code in PHP

注意事项

php最大执行时间好像是30秒,超过30秒会自动终止,因此调试的时候要修改一下时间,在php.ini 文件中修改最大运行时间为5分钟


max_execution_time=3000

拓展

hbuilder和vscode 配置xdebug时候是一样的,在浏览器打开文件hbuilder会自动命中断点

Detailed graphic explanation of how to debug visual studio code in PHP

The above is the detailed content of Detailed graphic explanation of how to debug visual studio code in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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 admin@php.cn