pecl install - how to specify options?
Asked Answered
A

3

5

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.

Amaliaamalie answered 20/1, 2020 at 9:33 Comment(4)
Does this answer your question? Install PECL modules without the promptsCoit
Not at all, I found that already.Amaliaamalie
Pinging OP @Amaliaamalie - have you found a satisfactory solution?Quidnunc
@SzczepanHołyszewski I did not.Amaliaamalie
R
7

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
Rist answered 14/7, 2022 at 13:39 Comment(3)
Nice! What version of PHP / Pecl implements this?Amaliaamalie
@Amaliaamalie It looks like it's been there since Nov 2019 / v.1.10.10: github.com/pear/pear-core/pull/90, github.com/pear/pear-core/commit/…Rist
is same: pecl install -D ...Parabasis
S
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 ...

Salvatore answered 20/1, 2020 at 9:42 Comment(10)
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.Amaliaamalie
well, at first I must not recommend pecl at all - you should use modern library for loop events. You may choose here: github.com/ziadoz/awesome-php#eventSalvatore
And I updated answet to be more flexibe to your needsSalvatore
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).Amaliaamalie
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?Amaliaamalie
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 modeSalvatore
@Amaliaamalie I added solution specifically for docker, check it outSalvatore
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 gist.github.com/enumag/fccf3d7182b421c4226d85af68b2bc9eAmaliaamalie
As for docker-php-ext-install event, that also fails with similar error. Apparently this command doesn't at all for pecl extensions.Amaliaamalie
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.Amaliaamalie
G
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 ...
Gudrun answered 22/12, 2021 at 7:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.