Skip to content

phar 打包

phar 是 PHP 里类似于 JAR 的一种打包文件,你可以利用 phar 将你的 webman 项目打包成单个 phar 文件,方便部署。

这里非常感谢 fuzqing 的 PR.

注意 需要关闭 php.ini 的 phar 配置选项,既设置 phar.readonly = 0

安装命令行工具

composer require webman/console

打包

在 webman 项目根目录执行命令 php webman phar:pack 会在 bulid 目录生成一个 webman.phar 文件。

打包相关配置在 config/plugin/webman/console/app.php

启动停止相关命令

启动php webman.phar startphp webman.phar start -d

停止php webman.phar stop

查看状态php webman.phar status

查看连接状态php webman.phar connections

重启php webman.phar restartphp webman.phar restart -d

说明

  • 打包后的项目不支持 reload,更新代码需要 restart 重启

  • 为了避免打包文件尺寸过大占用过多内存,可以设置 config/plugin/webman/console/app.php 里的 exclude_pattern exclude_files 选项将排除不必要的文件。

  • 运行 webman.phar 后会在 webman.phar 所在目录生成 runtime 目录,用于存放日志等临时文件。

  • 如果你的项目里使用了.env 文件,需要将.env 文件放在 webman.phar 所在目录。

  • 切勿将用户上传的文件存储在 phar 包中,因为以 phar:// 协议操作用户上传的文件是非常危险的 (phar 反序列化漏洞)。用户上传的文件必须单独存储在 phar 包之外的磁盘中,参见下面。

  • 如果你的业务需要上传文件到 public 目录,需要将 public 目录独立出来放在 webman.phar 所在目录,这时候需要配置 config/app.php

'public_path' => base_path(false) . DIRECTORY_SEPARATOR . 'public',

业务可以使用助手函数 public_path($文件相对位置) 找到实际的 public 目录位置。

  • 注意 webman.phar 不支持在 windows 下开启自定义进程

基于 MIT 许可发布