# Disable interactive mode (-a) if readline not available

- Thread: https://externals.io/message/114426
- Original archive: https://news-web.php.net/php.internals/114426
- Started by Nikita Popov on 2021-05-12T08:12:43+00:00
- Messages: 16
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #114426 — Nikita Popov — 2021-05-12T08:12:43+00:00

URL: https://externals.io/message/114426#114426

Hi internals,

If the readline extension is enabled, PHP provides an interactive shell
under -a. If it is not enabled, it falls back to an "interactive mode"
(yes, the difference between "interactive shell" and "interactive mode" is
important here). The interactive mode is simply an stdin input, which needs
to be terminated using Ctrl+D. You can only run one script that way.

I think the current behavior is quite confusing, because it's really not
obvious that you ended up in this fallback mode (you need to know the
difference between "shell" and "mode" in the output) and most people
wouldn't know what to do with it. The latest instance of this is
https://bugs.php.net/bug.php?id=81033.

I think we would be better off disabling -a completely if readline is not
available, and exit with a helpful error message. I've opened
https://github.com/php/php-src/pull/6976 to that effect. Does that sound
reasonable?

Regards,
Nikita

---

## #114427 — Moritz Friedrich — 2021-05-12T08:36:57+00:00

URL: https://externals.io/message/114426#114427 · In reply to: #114426

> Am 12.05.2021 um 10:12 schrieb Nikita Popov <nikita.ppv@gmail.com>:
> 
> Hi internals,
> 
> If the readline extension is enabled, PHP provides an interactive shell
> under -a. If it is not enabled, it falls back to an "interactive mode"
> (yes, the difference between "interactive shell" and "interactive mode" is
> important here). The interactive mode is simply an stdin input, which needs
> to be terminated using Ctrl+D. You can only run one script that way.
> 
> I think the current behavior is quite confusing, because it's really not
> obvious that you ended up in this fallback mode (you need to know the
> difference between "shell" and "mode" in the output) and most people
> wouldn't know what to do with it. The latest instance of this is
> https://bugs.php.net/bug.php?id=81033.
> 
> I think we would be better off disabling -a completely if readline is not
> available, and exit with a helpful error message. I've opened
> https://github.com/php/php-src/pull/6976 to that effect. Does that sound
> reasonable?
> 
> Regards,
> Nikita

Hi Nikita,
if I may ask, would it also be possible to have deadline as a mandatory 
dependency to always have the interactive shell available? Is there a good
reason to compile PHP without? Having a basic prompt available is really
handy at times — especially looking at Node.js with their ahead-completion
and general UX.
The same has been done for other PHP modules in the past, so I wonder if 
we could simply have readline as a guarantee.

Regards,
Moritz

---

## #114428 — Nikita Popov — 2021-05-12T08:48:17+00:00

URL: https://externals.io/message/114426#114428 · In reply to: #114427

>
> > […]
> is
> > […]
> needs
> > […]
>
> Hi Nikita,
> if I may ask, would it also be possible to have deadline as a mandatory
> dependency to always have the interactive shell available? Is there a good
> reason to compile PHP without? Having a basic prompt available is really
> handy at times — especially looking at Node.js with their ahead-completion
> and general UX.
> The same has been done for other PHP modules in the past, so I wonder if
> we could simply have readline as a guarantee.


The readline extension has an external dependency on readline / libedit.
Making it a required extension would also make this a required dependency.
We avoid having dependencies for the minimal build. The only dependency we
currently have is libpcre, and we vendor that one. I doubt we'll want to
add a new vendored dependency, as they tend to be a major pain.

I personally do not use the interactive shell (and I think most people who
do use *an* interactive shell prefer psysh), so I don't think this can be
reasonably considered a "required" feature.

Regards,
Nikita

---

## #114430 — Joe Watkins — 2021-05-12T09:29:04+00:00

URL: https://externals.io/message/114426#114430 · In reply to: #114428

Morning Nikita,

+1 on the change to cli.

It can't really be a default extension right now because readline license
is not compatible:

https://github.com/php/php-src/pull/3823

Even without the license problem, I'm not convinced of the value of adding
the dependency: Because of this long standing strange behaviour, I don't
really think the interactive shell is well used.

Cheers
Joe



> 
>
> > […]
> not
> > […]
> not
> > […]
> sound
> > […]
> good
> > […]
> ahead-completion
> > […]
>
>
> The readline extension has an external dependency on readline / libedit.
> Making it a required extension would also make this a required dependency.
> We avoid having dependencies for the minimal build. The only dependency we
> currently have is libpcre, and we vendor that one. I doubt we'll want to
> add a new vendored dependency, as they tend to be a major pain.
>
> I personally do not use the interactive shell (and I think most people who
> do use *an* interactive shell prefer psysh), so I don't think this can be
> reasonably considered a "required" feature.
>
> Regards,
> Nikita

---

## #114432 — Pierre — 2021-05-12T09:39:11+00:00

URL: https://externals.io/message/114426#114432 · In reply to: #114430

Le 12/05/2021 à 11:29, Joe Watkins a écrit :
> Morning Nikita,
>
> +1 on the change to cli.
>
> It can't really be a default extension right now because readline license
> is not compatible:
>
> https://github.com/php/php-src/pull/3823
>
> Even without the license problem, I'm not convinced of the value of adding
> the dependency: Because of this long standing strange behaviour, I don't
> really think the interactive shell is well used.

Hello,

I might be an exception, I don't know, but I do use it a lot (almost 
every day). I don't want to install psysh or anything like it, php -a is 
enough for what I do with it.

Regards,

Pierre

---

## #114433 — Michelangelo van Dam — 2021-05-12T09:44:26+00:00

URL: https://externals.io/message/114426#114433 · In reply to: #114432

> 
> 
> Le 12/05/2021 à 11:29, Joe Watkins a écrit :
> > […]
> 
> Hello,
> 
> I might be an exception, I don't know, but I do use it a lot (almost every day). I don't want to install psysh or anything like it, php -a is enough for what I do with it.
> 
> Regards,
> 
> Pierre
> 
> -- 
> 
> To unsubscribe, visit: https://www.php.net/unsub.php
> 

Hello,

I’m using php -a daily on CLI to quickly try out hypothesis or evaluate expressions. No interest in using other tools.

Cheers,

Michelangelo

---

## #114435 — Joe Watkins — 2021-05-12T09:49:58+00:00

URL: https://externals.io/message/114426#114435 · In reply to: #114432

Morning,

Still I think heavy use has to be the exception, especially heavy use where
readline is not available (because it's questionably useful).

Cheers
Joe



> Le 12/05/2021 à 11:29, Joe Watkins a écrit :
> > […]
> adding
> > […]
>
> Hello,
>
> I might be an exception, I don't know, but I do use it a lot (almost
> every day). I don't want to install psysh or anything like it, php -a is
> enough for what I do with it.
>
> Regards,
>
> Pierre
>
> --
> 
> To unsubscribe, visit: https://www.php.net/unsub.php

---

## #114437 — Nikita Popov — 2021-05-12T09:51:50+00:00

URL: https://externals.io/message/114426#114437 · In reply to: #114433

On Wed, May 12, 2021 at 11:44 AM Michelangelo van Dam <dragonbe@gmail.com>
wrote:

>
>
> > […]
> license
> > […]
> adding
> > […]
> every day). I don't want to install psysh or anything like it, php -a is
> enough for what I do with it.
> > […]
>
> Hello,
>
> I’m using php -a daily on CLI to quickly try out hypothesis or evaluate
> expressions. No interest in using other tools.
>

Everyone, let's please keep discussion relating to the interactive shell
*with* readline out of this thread. Unless you are using the interactive
mode *without* readline, your usage will not be affected by the proposed
change.

If you want to discuss improvements to php -a *with* readline, then please
do so in a different thread.

Regards,
Nikita

---

## #114439 — Christoph M. Becker — 2021-05-12T13:42:00+00:00

URL: https://externals.io/message/114426#114439 · In reply to: #114426

> I think we would be better off disabling -a completely if readline is not
> available, and exit with a helpful error message. I've opened
> https://github.com/php/php-src/pull/6976 to that effect. Does that sound
> reasonable?

I'm in favor of dropping the interactive mode.  Thank you for the PR!

I wonder, though, if there is even a difference between `php -a`
(without readline) and `php` (besides the "interactive mode" message).

--
Christoph M. Becker

---

## #114440 — Nikita Popov — 2021-05-12T13:53:17+00:00

URL: https://externals.io/message/114426#114440 · In reply to: #114439

On Wed, May 12, 2021 at 3:42 PM Christoph M. Becker <cmbecker69@gmx.de>
wrote:

> 
>
> > […]
>
> I'm in favor of dropping the interactive mode.  Thank you for the PR!
>
> I wonder, though, if there is even a difference between `php -a`
> (without readline) and `php` (besides the "interactive mode" message).
>

I don't think there's any difference.

Nikita

---

## #114441 — Bob Weinand — 2021-05-12T14:15:46+00:00

URL: https://externals.io/message/114426#114441 · In reply to: #114426

> Am 12.05.2021 um 10:12 schrieb Nikita Popov <nikita.ppv@gmail.com>:
> 
> Hi internals,
> 
> If the readline extension is enabled, PHP provides an interactive shell
> under -a. If it is not enabled, it falls back to an "interactive mode"
> (yes, the difference between "interactive shell" and "interactive mode" is
> important here). The interactive mode is simply an stdin input, which needs
> to be terminated using Ctrl+D. You can only run one script that way.
> 
> I think the current behavior is quite confusing, because it's really not
> obvious that you ended up in this fallback mode (you need to know the
> difference between "shell" and "mode" in the output) and most people
> wouldn't know what to do with it. The latest instance of this is
> https://bugs.php.net/bug.php?id=81033.
> 
> I think we would be better off disabling -a completely if readline is not
> available, and exit with a helpful error message. I've opened
> https://github.com/php/php-src/pull/6976 to that effect. Does that sound
> reasonable?
> 
> Regards,
> Nikita

Hey Nikita,

yes, please merge that PR, I've been annoyed more than once that the php -a was not actually interactive despite a seemingly good message. (and as cmb noted, it's effectively identical to bare php without args.)

Bob

---

## #114448 — Aaron Piotrowski — 2021-05-12T15:39:26+00:00

URL: https://externals.io/message/114426#114448 · In reply to: #114426

> 
> 
> Hi internals,
> 
> If the readline extension is enabled, PHP provides an interactive shell
> under -a. If it is not enabled, it falls back to an "interactive mode"
> (yes, the difference between "interactive shell" and "interactive mode" is
> important here). The interactive mode is simply an stdin input, which needs
> to be terminated using Ctrl+D. You can only run one script that way.
> 
> I think the current behavior is quite confusing, because it's really not
> obvious that you ended up in this fallback mode (you need to know the
> difference between "shell" and "mode" in the output) and most people
> wouldn't know what to do with it. The latest instance of this is
> https://bugs.php.net/bug.php?id=81033.
> 
> I think we would be better off disabling -a completely if readline is not
> available, and exit with a helpful error message. I've opened
> https://github.com/php/php-src/pull/6976 to that effect. Does that sound
> reasonable?
> 
> Regards,
> Nikita

This would have been helpful several years ago when I started compiling PHP myself and was confused why `php -a` broke. An error message would have saved me some time. So yes, please, merge it.

Aaron Piotrowski

---

## #114450 — David Gebler — 2021-05-12T16:13:10+00:00

URL: https://externals.io/message/114426#114450 · In reply to: #114426

>
> I think we would be better off disabling -a completely if readline is not
> available, and exit with a helpful error message. I've opened
> https://github.com/php/php-src/pull/6976 to that effect. Does that sound
> reasonable?
>
> Regards,
> Nikita
>

+1 for this, the shell is very useful but "interactive mode", the evidence
is clear has a tendency to confuse people.
To invert the question, would anyone have a good justification to NOT
remove interactive mode?

---

## #114452 — Levi Morrison via internals — 2021-05-12T16:21:19+00:00

URL: https://externals.io/message/114426#114452 · In reply to: #114450

>
> 
>
> > […]
>
> +1 for this, the shell is very useful but "interactive mode", the evidence
> is clear has a tendency to confuse people.
> To invert the question, would anyone have a good justification to NOT
> remove interactive mode?

I've never once ran `php -a` and wanted the behavior that comes if you
don't have readline or libedit available. As has been mentioned, if
you want that behavior run `php` without -a. There's no loss of
functionality here, methinks. As long as `php -a` gives a sensible
message if it wasn't built with readline or libedit that says such:

    The interactive shell requires libedit or readline support, which
this build does not have.
    Run php without -a to get an interactive mode instead.

Or something.

---

## #114456 — Rowan Tommins — 2021-05-12T20:46:39+00:00

URL: https://externals.io/message/114426#114456 · In reply to: #114452

>      The interactive shell requires libedit or readline support, which
> this build does not have.
>      Run php without -a to get an interactive mode instead.


Unless I'm missing something, the default CLI mode (php without -a) is 
"interactive PHP" only if you consider "cat > foo.txt" to be an 
"interactive editor". You can type a complete script (remembering to 
start with "<?php"), hit Ctrl-D (if you happen to know that that means 
"end of file") and it will execute it, then exit.

I too have been stung by accidentally triggering this mode without 
readline enabled, and would be happy to see Nikita's patch merged.

Regards,

-- 
Rowan Tommins
[IMSoP]

---

## #114485 — Niklas Keller — 2021-05-15T06:35:51+00:00

URL: https://externals.io/message/114426#114485 · In reply to: #114456

Hey all,

please remember that you can also use php -r to quickly evaluate
expressions, e.g. generating a random password:

php -r 'var_dump(bin2hex(random_bytes(16)));'

I'm in favor of removal without readline.

Best,
Niklas

Rowan Tommins <rowan.collins@gmail.com> schrieb am Mi., 12. Mai 2021, 22:46:

> 
> > […]
>
>
> Unless I'm missing something, the default CLI mode (php without -a) is
> "interactive PHP" only if you consider "cat > foo.txt" to be an
> "interactive editor". You can type a complete script (remembering to
> start with "<?php"), hit Ctrl-D (if you happen to know that that means
> "end of file") and it will execute it, then exit.
>
> I too have been stung by accidentally triggering this mode without
> readline enabled, and would be happy to see Nikita's patch merged.
>
> Regards,
>
> --
> Rowan Tommins
> [IMSoP]
>
> --
> 
> To unsubscribe, visit: https://www.php.net/unsub.php
