valet-phpstorm-xdebug-phpunit-qcachegrind(mac)

  • 可使用 command+, 快捷键打开 PHPStorm Preferences页面

  • 在 Preferences 页面可以直接搜索要配置的项目

  • 可使用 control+alt+d 快捷键打开 PHPStorm Debug 设置

一、配置单 php 文件的 Debug

1、PHPStorm: Preferences > Languages & Frameworks > PHP
    > PHP language level: 7.2
    > CLI interpreter: PHP 7.2.4

2、PHPStorm: Run > Edit Configurations.. > + > PHP Script, 添加 php 文件。
    或直接在要调试的 php 文件中,`control+alt+d` > xxx.php(PHP Script)

二、配置 Laravel 的 Debug

1、修改 xdebug.ini

xdebug.remote_autostart=1
xdebug.default_enable=1
xdebug.remote_port=9001 ;xdebug的端口,默认为9000,我习惯用9001
xdebug.remote_host=127.0.0.1
xdebug.remote_connect_back=1
xdebug.remote_enable=1
xdebug.idekey=PHPSTORM

如需开启性能分析,还需添加下列信息,开启后会严重拖慢 laravel 打开速度

2、 重启 php-fpm

3、配置 PhpStorm

4、对于 valet 项目,还需配置 valet 路径至 include path:

5、监听来自页面的 xdebug 请求,即浏览器中打开网页后自动跳转到 PHPStorm 的断点上:

首先在 PHPStorm 中开启监听:

然后再 Web 端开启 XDEBUG_SESSION:

方法一:

在请求 URL 中添加 XDEBUG_SESSION_START 参数(可以为任意值, 例如:XDEBUG_SESSION_START=1),

代码中设置断点,然后访问URL:

即可进入设置过的断点。

方法二:

cookie 中设置 XDEBUG_SESSION。使用方法一就会自动设置此 cookie 值,有效期 1小时。

Laravel 项目中可以如下配置:

三、配置 PHP Unit

1、安装phpunit

2、配置 ~/.bash_profile

这样在 Terminal 中可以使用 t 直接运行。

3、配置 PHPStorm 中 phpunit 路径

这样就可以在 PHPStorm 中对 Laravel Test 文件使用 control+alt+d 执行 PHPUnit 了。

四、安装qcachegrind(mac下的图形化性能分析软件)

还可以把 qcachegrind 添加到应用程序中:

解决 Call Graph 无法使用的问题:

以上命令会报错,因为mac系统有完整性保护,mac系统一些重要的系统目录禁止修改,即使是切换到root也不行。

这时,可暂时修改:

Last updated