swoole/swoole-cli

swoole-cli在linux下无法使用-a进入shell交互,提示:Interactive shell (-a) requires the readline extension.

maxiaozhi opened this issue · 7 comments

swoole-cli在linux下无法使用-a进入shell交互,提示:Interactive shell (-a) requires the readline extension.
猜测应该是readline扩展加载比较滞后导致的

正在研究中

经过测试验证发现 ,从 5.1.2 版本开始,出现了这种情况。
macos 环境下,未复现此问题

应该是升级 PHP 源码 把修改覆盖了 update php to 8.1.27

产生的原因: sync-source-code.php 代码有缺陷,同步readline 扩展未做处理

修复启用 readline 方法:
0401aed#diff-796648a9b6c2460b3c37064323891656592e446ee721d7ed5652b5bc68307ea8R747

修复方法:

fix: #799

经过测试验证发现 ,从 5.1.2 版本开始,出现了这种情况。 macos 环境下,未复现此问题

印象中以前版本的确不存在该问题,就是从5.1.x版本出现了该问题

通用shell 脚本解决

FOUND_DL_READLINE=$(grep -c '#ifdef COMPILE_DL_READLINE' ext/readline/readline_cli.c)

if test $[FOUND_DL_READLINE] -gt 0 ; then
    # 获得待删除 区间
    START_LINE_NUM=$(sed  -n "/#ifdef COMPILE_DL_READLINE/=" ext/readline/readline_cli.c)
    START_LINE_NUM=$(($START_LINE_NUM - 1))
    END_LINE_NUM=$(sed  -n "/PHP_MINIT_FUNCTION(cli_readline)/=" ext/readline/readline_cli.c)
    END_LINE_NUM=$(($END_LINE_NUM - 5))

    sed -i.backup "${START_LINE_NUM},${END_LINE_NUM}d" ext/readline/readline_cli.c

    REPLACE_LINE_NUM=$(sed  -n "/#define GET_SHELL_CB(cb) (cb) = php_cli_get_shell_callbacks()/=" ext/readline/readline_cli.c)
    REPLACE_LINE_NUM=$(($REPLACE_LINE_NUM + 1))

    sed -i.backup "${REPLACE_LINE_NUM} s/.*/  /" ext/readline/readline_cli.c

fi

通用shell 脚本解决

FOUND_DL_READLINE=$(grep -c '#ifdef COMPILE_DL_READLINE' ext/readline/readline_cli.c)

if test $[FOUND_DL_READLINE] -gt 0 ; then
    # 获得待删除 区间
    START_LINE_NUM=$(sed  -n "/#ifdef COMPILE_DL_READLINE/=" ext/readline/readline_cli.c)
    START_LINE_NUM=$(($START_LINE_NUM - 1))
    END_LINE_NUM=$(sed  -n "/PHP_MINIT_FUNCTION(cli_readline)/=" ext/readline/readline_cli.c)
    END_LINE_NUM=$(($END_LINE_NUM - 5))

    sed -i.backup "${START_LINE_NUM},${END_LINE_NUM}d" ext/readline/readline_cli.c

    REPLACE_LINE_NUM=$(sed  -n "/#define GET_SHELL_CB(cb) (cb) = php_cli_get_shell_callbacks()/=" ext/readline/readline_cli.c)
    REPLACE_LINE_NUM=$(($REPLACE_LINE_NUM + 1))

    sed -i.backup "${REPLACE_LINE_NUM} s/.*/  /" ext/readline/readline_cli.c

fi

嗯,我这边已经试过编译成功了