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.
Have a look at either running php.exe with the -a
argument, or maybe the phpsh project.
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.
@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%
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".
I found these two on github as well:
ubermuda/PHPInteractiveShell https://github.com/ubermuda/PHPInteractiveShell
d11wtq/boris · non windows https://github.com/d11wtq/boris
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.