hyperf开发技巧

  • 使用yasd像xdebug一样调试代码

# 按照文档安装扩展然后进行如下配置
[yasd]
zend_extension=yasd
yasd.debug_mode=remote
; 这个ip是ide的实体机ip
yasd.remote_host=172.30.0.1
yasd.remote_port=9013

# 配置.vscode/launch.json, configurations 里面的port一致即可
{
    "name": "Listen for Xdebug",
    "type": "php",
    "request": "launch",
    "port": 9013
}

# 特别注意swoole的worker_num修改为1

# vscodeF5运行代码会监听端口, 然后命令运行代码使用 -e 参数, h会提示
php -e bin/hyperf start
# easyswoole
php -e vendor/bin/easyswoole server start

# 如果提示,检查ip和端口
[yasd] Connect IDE failed (Connection refused), please check that the IDE is in a listening stateful

# 如果虚拟机和实体机的路径不一致(windows开发linux的路径),加上pathMappings对路径进行映射,键就是实际(如虚拟机)的目录;值使用${workspaceFolder}变量,当前ide打开的工作目录

{
    "name": "Listen for Xdebug",
    "type": "php",
    "request": "launch",
    "port": 9013,
    "pathMappings": {
        "/home/jcleng/desktop/work/www/swoole_demo": "${workspaceFolder}"
    }
},