How to run php in interactive CLI in Windows

丶灬走出姿态 提交于 2019-12-11 13:59:26

问题


I would like to run PHP in a command-line-interface and I would like to get output after every line I write.

I have php.exe in my PATH environment variable. I use php -r "echo 'Hello world'" or

php -a 
Interactive mode enabled 
<?php
echo "hello world"
?>
^Z

But I want a real php shell, which reacts after every command. I have used something similar in Python. Is this possible in PHP? You can recommend a program that has this feature.


回答1:


For a powerful interactive PHP CLI, I suggest you take a look at PsySH. It's very easy to install, you just have to run one command:

composer g require psy/psysh:@stable

Then make sure you have added the composer vendor directory to the PATH system variable (instructions) by appending the following:

;C:\Users\[username]\AppData\Roaming\Composer\vendor\bin\

Then start it just run:

psysh

If you want an even console better experience, I suggest you use cmder instead of the Windows Command Prompt.




回答2:


As 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.

You need to run the program whith the modifier "-a"

php -a

Then, you need to recompile php whith "--with-readline" to enable this feature and works like in phyton.

I hope I have been helpful.



来源:https://stackoverflow.com/questions/29035294/how-to-run-php-in-interactive-cli-in-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!