4

I'm trying to install event extension for PHP using pecl. During the installation I get several prompts:

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] : 

But ofc that only happens in the interactive mode. I need to do this without interaction, for instance in Dockerfile. The default values don't work for me so I need to change them with command line options. How?

Keep in mind that I need to answer differently for each question so yes '' | pecl install ... doesn't work at all. Also one of the questions needs a path and not yes/no.

enumag
  • 830
  • 11
  • 21

3 Answers3

3

It's now possible to pass configuration options to pecl install via --configureoptions.

You'll want to find your package's package.xml file to see what options are configurable. For the event package, you'll go here:

https://bitbucket.org/osmanov/pecl-event/src/master/package.xml

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

<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"/>

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

pecl install --configureoptions 'enable-event-debug="no" with-event-libevent-dir="/my/dir" with-event-ns="yes"' event
Ben Y
  • 1,711
  • 1
  • 25
  • 37
  • Nice! What version of PHP / Pecl implements this? – enumag Jul 14 '22 at 20:51
  • @enumag It looks like it's been there since Nov 2019 / v.1.10.10: https://github.com/pear/pear-core/pull/90, https://github.com/pear/pear-core/commit/0b379be82b165d4f37b12d7e63c658ba620861e4 – Ben Y Jul 15 '22 at 05:11
  • is same: pecl install -D ... – Yifan Nov 10 '22 at 08:25
1

Non-interactive mode for pecl is not yet available. It can be supplemented with yes command. Command outputs affirmatives until terminated.

You may use yes with pipe like this: yes '' | pecl install ...

Edit: If you are not in need output yes every iteration, just echo your answers like echo 'yes\n no\n ...' | pecl install ...

More edit: If you are using this solution in docker, in Dockerfile you may use command docker-php-ext-install event and then docker-php-ext-configure ...

Tom
  • 71
  • 1
  • 11
  • I don't want to answer yes to all prompts though. I need to answer differently for different question. Also one prompt asks for a path. – enumag Jan 20 '20 at 09:43
  • well, at first I must not recommend pecl at all - you should use modern library for loop events. You may choose here: https://github.com/ziadoz/awesome-php#event – Tom Jan 20 '20 at 10:03
  • And I updated answet to be more flexibe to your needs – Tom Jan 20 '20 at 10:03
  • All event loop libraries require or at least heavily recommend using some PHP extension for better performance - usually ev, event or uv. How do I install any of these extensions without pecl? For the record I'm using the Amp library (fist one listed on the list you linked). – enumag Jan 20 '20 at 10:40
  • Btw using `echo 'answers' | pecl install...` won't work because the prompts don't happen at all in non-interactive mode. Is there a way to force the prompts to appear anyway so that I can use your way? – enumag Jan 20 '20 at 10:44
  • In dockerfile (as you stated) you can use interactive mode - fe. command `echo 'no\n' | pecl install ...` will work. Scripted does not mean non-interactive mode – Tom Jan 20 '20 at 11:54
  • @enumag I added solution specifically for docker, check it out – Tom Jan 20 '20 at 12:07
  • Unfortunately it doesn't work. I don't know why. `php -r "var_dump(extension_loaded('event'));"` returns true. But `docker-php-ext-configure event --with-event-openssl=no` fails with https://gist.github.com/enumag/fccf3d7182b421c4226d85af68b2bc9e – enumag Jan 20 '20 at 13:10
  • As for `docker-php-ext-install event`, that also fails with similar error. Apparently this command doesn't at all for pecl extensions. – enumag Jan 20 '20 at 13:18
  • I tried your `echo 'yes\n no\n ...' | pecl install ...` trick but it doesn't work either - the extension is still installed with the default values instead of what I specified in the echo. – enumag Jan 20 '20 at 13:27
1

I'm using PHP workerman these days and also meet this problem when install event extension in Docker. Following workerman's documents, event should be configured as:

  • do NOT include libevent OpenSSL support
  • ENABLE PHP Namespace for all Event classes

which means one should type no for interactive question Include libevent OpenSSL support [yes] : and yes for Include libevent OpenSSL support [yes] :, while just leave enter for other questions.

You may try THIS solution (and also put RUN in the head in Dockerfile):

printf "\n\n\n\n\nno\nyes\n\n" | pecl install event

echo '\n\n\n\n\nno\nyes\n\n' do NOT work since it seems not be used as interactive answers, which sends whole string as the configuration parameter value, and you may see this:

running: /tmp/pear/temp/event/configure --with-php-config=/usr/bin/php-config --enable-event-debug=\n\n\n\n\nno\nyes\n\n ...
Yu Sun
  • 21
  • 4