1

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.

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This is awesome. I think it's basically the only REPL for Windows. It's written in fully PHP. N.B. you don't need cmder, if you combine the GNU tools that come natively compiled for Windows with Git and the clink readline tool, you have a pretty good DOS prompt.
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.