Interactive shellAs of PHP 5.1.0, the CLI SAPI provides an interactive shell using the -a option if PHP is compiled with the --with-readline option. Using the interactive shell you are able to type PHP code and have it executed directly. Example #1 Executing code using the interactive shell $ php -a Interactive shell php > echo 5+8; 13 php > function addTwo($n) php > { php { return $n + 2; php { } php > var_dump(addtwo(2)); int(4) php > The interactive shell also features tab completion for functions, constants, class names, variables, static method calls and class constants. Example #2 Tab completion Pressing the tab key twice when there are multiple possible completions will result in a list of these completions: php > strp[TAB][TAB] strpbrk strpos strptime php > strp When there is only one possible completion, pressing tab once will complete the rest on the same line: php > strpt[TAB]ime( Completion will also work for names that have been defined during the current interactive shell session: php > $fooThisIsAReallyLongVariableName = 42; php > $foo[TAB]ThisIsAReallyLongVariableName The interactive shell stores your history which can be accessed using the up and down keys. The history is saved in the ~/.php_history file.
As of PHP 5.4.0, the CLI SAPI provides
the php.ini settings In PHP 5.4.0 it was also made possible to set php.ini settings in the interactive shell using a shorthand notation. Example #3 Setting php.ini settings in the interactive shell
The php > #cli.prompt=hello world :> hello world :> Using backticks it is possible to have PHP code executed in the prompt: php > #cli.prompt=`echo date('H:i:s');` php > 15:49:35 php > echo 'hi'; hi 15:49:43 php > sleep(2); 15:49:45 php > Setting the pager to less: php > #cli.pager=less php > phpinfo(); (output displayed in less) php >
The
|