在使用 micro:combine 打包 phar 时出现乱码
如题
会出现一大串乱码和无法找到 composer autoload 的库
中文可以输出
使用 box 打包
micro 有以下扩展 curl,openssl,phar,swoole,zstd 并且开启 --with-micro-fake-cli
使用 php 运行原始 phar 可以正常运行
什么操作系统/架构?另外如果可以的话最好附上最小复现的 phar 和完整的编译命令。
什么操作系统/架构?另外如果可以的话最好附上最小复现的 phar 和完整的编译命令。
是Linux x86_64 ubuntu
什么操作系统/架构?另外如果可以的话最好附上最小复现的 phar 和完整的编译命令。
完整编译指令:
bin/spc doctor --auto-fix
bin/spc download --for-extensions=openssl,swoole,zip,pcntl,phar,zstd --with-php=8.3
bin/spc build --build-micro curl,openssl,phar,swoole,zlib --with-libs=zstd --with-micro-fake-cli
bin/spc micro:combine xxxx.phar --output=php-openbmclapi-linux-x86_64
最小包我复现一下
复现了,但是没乱码,class没找到还是有的 我刚刚临时编译环境的 box 可能是老版本,会报 Deprecated 但应该不影响运行 https://f.ws59.cn/f/efk79656lpp
require 一行使用绝对路径呢?require __DIR__ . "/vendor/autoload.php"? 一般情况下 phar 运行找不到类都是相对路径或绝对路径找错了导致的。
require一行使用绝对路径呢?require __DIR__ . "/vendor/autoload.php"? 一般情况下 phar 运行找不到类都是相对路径或绝对路径找错了导致的。
我用的是 require "vendor/autoload.php" 我尝试一下
我使用了 require_once(__DIR__ . '/vendor/autoload.php'); 但是还是一样,我觉得是乱码的问题
并且swoole的协程执行会错乱 但是我又无法找到一个最小复现,我还得再看看
隔壁问题也有类似的问题,那个是打包 hyperf。很可能是打包方法的问题,如果可以的话就用 static-php-cli 自己的 box.json 改一改试一下(box 最新版),spc 自身打包也会验证,都是没问题的。
隔壁问题也有类似的问题,那个是打包 hyperf。很可能是打包方法的问题,如果可以的话就用 static-php-cli 自己的 box.json 改一改试一下(box 最新版),spc 自身打包也会验证,都是没问题的。
好,我晚点试试
看了下可能是 swoole 的 bug,换成 swow 或其他就没问题了,但目前我和 micro 作者都还没找到 swoole 上面哪里出了问题。
这个问题很奇怪,我用我自己开发的基于 Swoole 的框架打包成二进制就可以运行,但 Hyperf 就不行。初步怀疑是 Hyperf 打包有点什么问题,或者 Swoole 的 Hook 在 phpmicro 与 Phar 的 Hook 中有 Bug。
@crazywhalecc I encounter this issue when combining Symfony CLI, after some debugging it seem swoole hooks on file function caused this error.
It fixed by removing file hook flags
Runtime::setHookFlags(SWOOLE_HOOK_ALL & ~SWOOLE_HOOK_FILE);
Somehow I believe it related with this issue: https://github.com/php-runtime/runtime/issues/171 this supposed to fix in v6 but I havent tried it yet
@praswicaksono Thank you for the information. I have tested that removing the file hook is indeed possible, but this problem still exists in the latest swoole.
Tracked in #477