is there a simple php shell for windows?

2019-03-13 02:17发布

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.

9条回答
贪生不怕死
2楼-- · 2019-03-13 02:30

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.

查看更多
对你真心纯属浪费
3楼-- · 2019-03-13 02:43

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.

查看更多
ら.Afraid
4楼-- · 2019-03-13 02:45

@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:

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

  2. new a Windows environment variable, key: shell.php, value: "C:\Program Files\php-5.6.12-Win32-VC11-x64"

  3. restart computer

  4. use anywhere in the system:

    php %shell.php%

查看更多
女痞
5楼-- · 2019-03-13 02:47

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.

查看更多
姐就是有狂的资本
6楼-- · 2019-03-13 02:48

There is the windows command line for PHP: http://php.net/manual/en/install.windows.commandline.php

查看更多
够拽才男人
7楼-- · 2019-03-13 02:49

Have a look at either running php.exe with the -a argument, or maybe the phpsh project.

查看更多
登录 后发表回答