is there a simple php shell for windows?

前端 未结 9 1819
迷失自我
迷失自我 2021-02-04 11:25

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条回答
  • 2021-02-04 12:17

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

    0 讨论(0)
  • 2021-02-04 12:18

    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.

    0 讨论(0)
  • 2021-02-04 12:20

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

    0 讨论(0)
  • 2021-02-04 12:21

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

    0 讨论(0)
  • 2021-02-04 12:21

    I found these two on github as well:

    • ubermuda/PHPInteractiveShell https://github.com/ubermuda/PHPInteractiveShell

    • d11wtq/boris · non windows https://github.com/d11wtq/boris

    0 讨论(0)
  • 2021-02-04 12:23

    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.

    0 讨论(0)
提交回复
热议问题