WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: when using php, how to use Interactive mode?  (Read 2144 times)

Offline simond

  • Newbie
  • *
  • Posts: 8
when using php, how to use Interactive mode?
« on: October 14, 2019, 10:05:15 PM »
I tried php5 and php7-cli on tc10

after entering command "php -a"
it printed "Interactive mode enabled" and then hung,
without giving a "php >" prompt

is there anything else needed for Interactive mode?

Code: [Select]
tc@box:~$ version
10.1
tc@box:~$ which php
/usr/local/bin/php
tc@box:~$ php -v
PHP 7.3.7(cli)...
tc@box:~$ php -a
Interactive mode enabled

Offline simond

  • Newbie
  • *
  • Posts: 8
Re: when using php, how to use Interactive mode?
« Reply #1 on: October 14, 2019, 10:18:09 PM »
it looks like that I need to compile php myself and add readline support?


https://www.php.net/manual/en/features.commandline.interactive.php

Quote
If you type 'php -a' and get a response of 'Interactive Shell' followed by a 'php>' prompt, you have interactive shell available (PHP was compiled with readline support). If instead you get a response of 'Interactive mode enabled', you DO NOT have interactive shell available and this article does not apply to you.

You can also check 'php -m' and see if readline is listed in the output - if not, you don't have interactive shell.

Interactive mode is essentially like running php with stdin as the file input. You just type code, and when you're done (Ctrl-D), php executes whatever you typed as if it were a normal PHP (PHTML) file - hence you start in interactive mode with '<?php' in order to execute code.

Interactive shell evaluates every expression as you complete it (with ; or }), reports errors without terminating execution, and supports standard shell functionality via readline (history, tab completion, etc). It's an enhanced version of interactive mode that is ONLY available if you have the required libraries, and is an actual PHP shell that interprets everything you type as PHP code - using '<?php' will cause a parse error.

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14545
Re: when using php, how to use Interactive mode?
« Reply #2 on: October 14, 2019, 10:24:19 PM »
Is the readline extension loaded?

Offline simond

  • Newbie
  • *
  • Posts: 8
Re: when using php, how to use Interactive mode?
« Reply #3 on: October 15, 2019, 12:13:45 AM »
Is the readline extension loaded?

thank you.

after loading readline.tcz and adding  extension=readline to php.ini, it's ok now.