Reputation: 16415
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.
Upvotes: 1
Views: 1825
Reputation: 44566
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.
Upvotes: 2
Reputation: 41
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.
Upvotes: 1