Can not use command line interpreter

前端 未结 9 1036
盖世英雄少女心
盖世英雄少女心 2021-02-05 09:58

I have tried to execute simple php code in the php interpreter. When I executed the command php -a I getting the message

Interactive mode ena

相关标签:
9条回答
  • 2021-02-05 10:39

    To check if you have readline module installed, type: php -m | grep readline

    If nothing displayed, install readline module: sudo apt-get install php5-readline

    After module installation you can recheck it's presence with previous command, than enter interactive mode with: php -a

    0 讨论(0)
  • 2021-02-05 10:46

    There seems to be a compilation / linkage error between your PHP and libreadline. This is documented in PHP Bug #48759.

    • Did you compile PHP by yourself? Did you play around with --configure and didn't do a proper make clean before your final build?
    • Does php -m list readline as enabled feature? (Is PHP built with option --with-readline)
    • What is you php version?
    • What distribution do you use?
    • Do you have the libreadline (the *-dev package) installed?
    0 讨论(0)
  • 2021-02-05 10:54

    You are in interactive mode, but without a prompt, since you may not have readline mode available. You just just need to start typing, and your commands will be evaluated after you press enter. It doesn't look like anything is going on, but if you enter, for example:

    <?php
    
    echo "hello world";
    
    ?>
    

    ...you will get output...

    If you enter braced blocks, they get evaluated after you press enter following the closing }

    <?php 
    for ($i = 0; $i < 5; $i++) {
      echo $i;
    }
    // prints 12345 after closing }
    

    Note that you must start with <?php or anything entered won't be evaluated.

    Update (years later):

    On a Red Hat (RHEL5) system running the vendor's security patched PHP 5.3.3, I have encountered an interactive mode which did not echo back following closing braces.

    Instead, the output buffer was not flushed until I pressed Ctrld. Effectively, this makes the interactive session one-time-use. Insert all code input, and Ctrld to return all output at once.

    0 讨论(0)
提交回复
热议问题