Is there a command line php shell available for windows? I looking for something similar to the python shell, that will allow me to open and immediately begin executing code.
问题:
回答1:
Have a look at either running php.exe with the -a
argument, or maybe the phpsh project.
回答2:
There is the windows command line for PHP: http://php.net/manual/en/install.windows.commandline.php
回答3:
Try this:
<?php
$fh = fopen('php://stdin', 'r');
$cmd = '';
$bcLvl = 0;
while (true)
{
$line = rtrim(fgets($fh));
$bcLvl += substr_count($line, '{') - substr_count($line, '}');
$cmd.= $line;
if ($bcLvl > 0 or substr($cmd, -1) !== ';')
continue;
eval($cmd);
$cmd = '';
}
Save this code to a file (eg shell.php) and then run it from console:
php shell.php
Hit CTRL+C to exit.
回答4:
Another simple variant, influenced by other answers. Create and run the following cmd-script:
@echo off
:loop
php.exe -r "while (true) { eval (fgets (STDIN) ); echo PHP_EOL; }"
goto loop
Immediate execution, Ctrl+C for exit. Insert correct path before "php.exe".
回答5:
There is php-shell - it is not great, but still way better than php -a
. (Also, it is dead simple to install, just run pear install http://jan.kneschke.de/assets/2007/2/17/PHP_Shell-0.3.1.tgz
.) There is also phpa-norl, but I haven't tried it.
回答6:
I found these two on github as well:
ubermuda/PHPInteractiveShell https://github.com/ubermuda/PHPInteractiveShell
d11wtq/boris · non windows https://github.com/d11wtq/boris
回答7:
PsySH is the best REPL shell I have seen recently. Tab-completion, phpdoc support, proper namespace handling, interactive debugging, plugin support and many more. It is pure PHP and has composer support so it should be easy to install on Windows. I have only tried it on Linux but looking at the code, it seems to even have some history support on OSes without readline.
回答8:
@Pavle Predic 's answer (https://stackoverflow.com/a/15742101/2752670) works for me on Windows.
But I want to use the shell.php
file anywhere, so my solution is:
new and save
shell.php
in php installed dir (or where else you like), e.g.C:\Program Files\php-5.6.12-Win32-VC11-x64\shell.php
new a Windows environment variable, key:
shell.php
, value:"C:\Program Files\php-5.6.12-Win32-VC11-x64"
restart computer
use anywhere in the system:
php %shell.php%
回答9:
Maybe answered - Read here: https://stackoverflow.com/a/19085620/2480481 I think i found easiest way to do it because im so interested to use myself :)
I try all options from here and from some other forums/pages... Windows cannot use readline.