在没有提示的情况下安装 PECL 模块

我刚刚在 Ubuntu Natty 上从源代码安装了 PHP。

我正在尝试使用 PECL 来安装额外的模块,比如 APC 和 Memcache:

pecl install apc

但是,我会收到提示,要求我确认一些事情。

如何使用 pecl 命令只接受默认值?我在一个留言板上看到了类似的东西: printf "yes\n" | pecl install pecl_http。但是,在 APC 的情况下,对于默认值为 no 的情况,这将回答 yes (我认为)。

先谢谢你。

37394 次浏览

The following code seems to work ok:

printf "\n" | pecl install apc

You can also replace apc with any other PECL package.

Cheers.

The "yes" command can do more than just type "yes"; it can type anything you want, over and over. Including an empty line, which is a good way to accept defaults.

I just needed this myself, so here is what worked well for me:

yes '' | pecl install -f apc

Obinwanne's Hill answer nailed it for me, so I'm not providing anything new here, but the following seems like the absolute shortest also without any fancy tools.

echo '' | pecl install apc

If you don't want give the same answer for every single prompt ("yes", "no", or ""), you can use --configureoptions to set specific values for each option (see the PECL manual).

You'll want to find your package's package.xml file to see what options are configurable. As an example, for the memcached package, you'd go here:

https://github.com/php-memcached-dev/php-memcached/blob/master/package.xml

Search for the <configureoption> tags, which in this case are:

<configureoption name="with-libmemcached-dir"     prompt="libmemcached directory"     default="no"/>
<configureoption name="with-zlib-dir"             prompt="zlib directory"             default="no"/>
<configureoption name="with-system-fastlz"        prompt="use system fastlz"          default="no"/>
<configureoption name="enable-memcached-igbinary" prompt="enable igbinary serializer" default="no"/>
<configureoption name="enable-memcached-msgpack"  prompt="enable msgpack serializer"  default="no"/>
<configureoption name="enable-memcached-json"     prompt="enable json serializer"     default="no"/>
<configureoption name="enable-memcached-protocol" prompt="enable server protocol"     default="no"/>
<configureoption name="enable-memcached-sasl"     prompt="enable sasl"                default="yes"/>
<configureoption name="enable-memcached-session"  prompt="enable sessions"            default="yes"/>

You can then pass these options along to the install command like so:

pecl install --configureoptions 'with-libmemcached-dir="no" with-zlib-dir="no" with-system-fastlz="no" enable-memcached-igbinary="yes" enable-memcached-msgpack="no" enable-memcached-json="no" enable-memcached-protocol="no" enable-memcached-sasl="yes" enable-memcached-session="yes"' memcached