php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81033 "Interactive Mode" Shell Hangs Indefinitely
Submitted: 2021-05-12 01:15 UTC Modified: 2021-05-12 11:44 UTC
From: security at paragonie dot com Assigned: cmb (profile)
Status: Not a bug Package: CGI/CLI related
PHP Version: master-Git-2021-05-12 (Git) OS: Ubuntu Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: security at paragonie dot com
New email:
PHP Version: OS:

 

 [2021-05-12 01:15 UTC] security at paragonie dot com
Description:
------------
Currently, I get the following result when I try to start an interactive session:

$ php -a
Interactive mode enabled


...but it hangs forever without prompting at all.

Using php -r works as expected:

$ php -r "echo 'hello world', PHP_EOL;"

$ php -v
PHP 8.1.0-dev (cli) (built: May 11 2021 21:07:43) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.0-dev, Copyright (c) Zend Technologies

The output of `php -r "phpinfo();"` is provided for completeness, although I do not think it's a configuration issue: https://gist.github.com/paragonie-security/92571c1121e4b16e019a82e810643bf6

Test script:
---------------
N/A just run `php -a` after building from master


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-05-12 02:08 UTC] requinix@php.net
-Summary: Interactive Shell Hangs Indefinitely +Summary: "Interactive Mode" Shell Hangs Indefinitely -Status: Open +Status: Feedback
 [2021-05-12 02:08 UTC] requinix@php.net
"Interactive mode enabled" means that it is reading from stdin but does not give you a full shell. The prompt you're expecting comes after an "Interactive shell" message.

Did you build with readline support? I don't see a --with-readline in your configure command. Or anything else, for that matter.
And just in case, what commit did you build from? Was it HEAD within the last ~16 hours?
 [2021-05-12 02:19 UTC] security at paragonie dot com
No, I did not --with-readline my ./configure command.

Yes, this was from HEAD on the master branch on Github: commit hash c945c399aa8051ae24c727d73c1ea0989f4d14d7

I've rebuilt it --with-readline and now I'm getting a weird error I don't understand, but it looks unrelated:

/usr/bin/ld: ext/reflection/php_reflection.o: in function `zim_ReflectionFiber___construct':
/home/scott/tmp/php-src/ext/reflection/php_reflection.c:6770: undefined reference to `zend_ce_fiber'
/usr/bin/ld: ext/reflection/php_reflection.o: in function `instanceof_function':
/home/scott/tmp/php-src/Zend/zend_operators.h:71: undefined reference to `zend_ce_fiber'
/usr/bin/ld: ext/reflection/php_reflection.o: in function `zim_ReflectionFiber___construct':
/home/scott/tmp/php-src/ext/reflection/php_reflection.c:6779: undefined reference to `zend_ce_fiber'
/usr/bin/ld: Zend/zend_execute_API.o: in function `init_executor':
/home/scott/tmp/php-src/Zend/zend_execute_API.c:195: undefined reference to `zend_fiber_init'
/usr/bin/ld: Zend/zend_default_classes.o: in function `zend_register_default_classes':
/home/scott/tmp/php-src/Zend/zend_default_classes.c:42: undefined reference to `zend_register_fiber_ce'
collect2: error: ld returned 1 exit status
make: *** [Makefile:274: sapi/cli/php] Error 1

> The prompt you're expecting comes after an "Interactive shell" message.

Interestingly, in my copy of PHP 8.0.x (provided by the ondrej packages for Ubuntu), I see the following prompt:

$ php8.0 -a
Interactive mode enabled

php > 

...Is this "Interactive mode enabled" / "Interactive shell" verbage something new to PHP 8.1? If that discrepancy isn't new, then readline might be a red herring, because it's working as expected when that prompt is displayed.
 [2021-05-12 04:06 UTC] requinix@php.net
-Status: Feedback +Status: Open
 [2021-05-12 04:06 UTC] requinix@php.net
> I've rebuilt it --with-readline and now I'm getting a weird error I don't
> understand, but it looks unrelated:

It sure does look unrelated, and c945c39 just built successfully for me. Did you reuse the same build directory from before? Did you make clean/git clean it before the second build?

> Interestingly, in my copy of PHP 8.0.x (provided by the ondrej packages for
> Ubuntu), I see the following prompt:

The relevant php_cli.c source [1] has changed some with 8.1, that is true:

if (interactive) {
	if (cli_shell_callbacks.cli_shell_run) {
		printf("Interactive shell\n\n");
	} else {
		printf("Interactive mode enabled\n\n");
		/* Treat as non-interactive apart from the stdin input */
		interactive = false;
	}

With 8.0 and before, there were still two messages displayed [2]: "shell" if you had specifically libreadline or libedit support and "mode" if not. What about building the same 8.0.x version yourself?


[1] https://github.com/php/php-src/blob/c945c39/sapi/cli/php_cli.c#L876
[2] https://github.com/php/php-src/blob/PHP-8.0.6/sapi/cli/php_cli.c#L867
 [2021-05-12 07:40 UTC] nikic@php.net
To clarify how this works: If you have readline enabled, then "Interactive shell" is printed, and you get a normal interactive shell, where you can enter something and press enter to run it. If readline is not enabled, then "Interactive mode enabled" is printed, and PHP just reads from stdin. You can use this mode by entering something and then using Ctrl+D to close stdin.

This is all pretty confusing, and the -a mode without readline seems pretty much useless to me. Maybe we should just completely disable -a if readline is not available?
 [2021-05-12 11:44 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Package: *General Issues +Package: CGI/CLI related -Assigned To: +Assigned To: cmb
 [2021-05-12 11:44 UTC] cmb@php.net
> With 8.0 and before, there were still two messages displayed
> [2]: "shell" if you had specifically libreadline or libedit
> support and "mode" if not.

The point is that since yesterday, readline support was determined
during build time, so when building ext/readline separately (like
it's usually done for Linux distros), you always got the
"Interactive mode" message, even when it actually may be the
interactive shell.
 [2021-05-12 11:44 UTC] cmb@php.net
s/since yesterday/before yesterday
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 22:01:28 2024 UTC