我正在尝试使用 pecl 为 PHP 安装
event
扩展。在安装过程中我得到几个提示:
Enable internal debugging in Event [no] :
Enable sockets support in Event [yes] :
libevent installation prefix [/usr] :
Include libevent's pthreads library and enable thread safety support in Event [no] :
Include libevent protocol-specific functionality support including HTTP, DNS, and RPC [yes] :
Include libevent OpenSSL support [yes] :
PHP Namespace for all Event classes [no] :
openssl installation prefix [no] :
但这只发生在交互模式下。我需要在没有交互的情况下执行此操作,例如在 Dockerfile 中。默认值对我不起作用,因此我需要使用命令行选项更改它们。怎么样?
请记住,我需要对每个问题做出不同的回答,所以
yes '' | pecl install ...
根本不起作用。还有一个问题需要一个路径而不是是/否。
现在可以通过
pecl install
将配置选项传递给--configureoptions
。
你会想要找到你的包的 package.xml 文件来查看哪些选项是可配置的。对于
event
包,你会去这里:
https://bitbucket.org/osmanov/pecl-event/src/master/package.xml
搜索
<configureoption>
标签,在本例中是:
<configureoption default="no" name="enable-event-debug" prompt="Enable internal debugging in Event"/>
<configureoption default="yes" name="enable-event-sockets" prompt="Enable sockets support in Event"/>
<configureoption default="/usr" name="with-event-libevent-dir" prompt="libevent installation prefix"/>
<configureoption default="no" name="with-event-pthreads" prompt="Include libevent's pthreads library and enable thread safety support in Event"/>
<configureoption default="yes" name="with-event-extra" prompt="Include libevent protocol-specific functionality support including HTTP, DNS, and RPC"/>
<configureoption default="yes" name="with-event-openssl" prompt="Include libevent OpenSSL support"/>
<configureoption default="no" name="with-event-ns" prompt="PHP Namespace for all Event classes"/>
<configureoption default="yes" name="with-openssl-dir" prompt="openssl installation prefix"/>
然后您可以像这样将这些选项传递给安装命令:
pecl install --configureoptions 'enable-event-debug="no" with-event-libevent-dir="/my/dir" with-event-ns="yes"' event
pecl 的非交互模式尚不可用。可以用
yes
命令补充。命令输出肯定,直到终止。
您可以像这样使用
yes
和管道:yes '' | pecl install ...
编辑:如果您不需要每次迭代都输出是,只需像
echo 'yes\n no\n ...' | pecl install ...
一样回应您的答案
更多编辑:如果您在 docker 中使用此解决方案,则在 Dockerfile 中您可以使用命令
docker-php-ext-install event
然后 docker-php-ext-configure ...
我这几天在用PHPworkerman,在Docker中安装
event
扩展时也遇到了这个问题。按照工人的文件,event
应该配置为:
这意味着应该为交互式问题
no
键入 Include libevent OpenSSL support [yes] :
,为 yes
键入 Include libevent OpenSSL support [yes] :
,而对于其他问题只需留下 enter
。
您可以尝试THIS解决方案(也可以将
RUN
放在Dockerfile
的头部):
printf "\n\n\n\n\nno\nyes\n\n" | pecl install event
echo '\n\n\n\n\nno\nyes\n\n'
不起作用,因为它似乎不能用作交互式答案,它将整个字符串作为配置参数值发送,您可能会看到:
running: /tmp/pear/temp/event/configure --with-php-config=/usr/bin/php-config --enable-event-debug=\n\n\n\n\nno\nyes\n\n ...