有一个简单的PHP shell的窗口


is there a simple php shell for windows?

是否有一个命令行php shell可用于windows?我在寻找类似于python shell的东西,它将允许我打开并立即开始执行代码。

有用于PHP的windows命令行:http://php.net/manual/en/install.windows.commandline.php

试试这个:

<?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 = '';
}

将此代码保存到一个文件中(例如shell.php),然后从控制台运行:

php shell.php

按CTRL+C退出

看看用-a参数运行php.exe,或者phpsh项目。

受其他答案影响的另一种简单变体。创建并运行以下命令行脚本:

@echo off
:loop
php.exe -r "while (true) { eval (fgets (STDIN) ); echo PHP_EOL; }"
goto loop

立即执行,Ctrl+C退出。在"php.exe"之前插入正确的路径

有php-shell -它不是很好,但仍然比php -a好。(此外,它是死简单的安装,只需运行pear install http://jan.kneschke.de/assets/2007/2/17/PHP_Shell-0.3.1.tgz。)还有phpa-norl,但我还没有尝试过。

我在github上也找到了这两个:

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

  • d11wtq/boris·non windowshttps://github.com/d11wtq/boris

PsySH是我最近看到的最好的REPL shell。Tab-completion, phpdoc支持,适当的命名空间处理,交互式调试,插件支持等等。它是纯PHP,并有作曲家的支持,所以它应该很容易安装在Windows上。我只在Linux上尝试过,但看看代码,它似乎甚至在没有readline的操作系统上有一些历史支持。

@Pavle Predic的答案(https://stackoverflow.com/a/15742101/2752670)适用于我的Windows。

但是我想在任何地方使用shell.php文件,所以我的解决方案是:

  1. 新建并保存shell.php在php安装目录(或其他你喜欢的地方),例如C:'Program Files'php-5.6.12-Win32-VC11-x64'shell.php

  2. new a Windows环境变量,键:shell.php,值:"C:'Program Files'php-5.6.12-Win32-VC11-x64"

  3. 重启计算机

  4. 在系统的任何地方使用:

    php %shell.php%

可能答案-阅读这里:https://stackoverflow.com/a/19085620/2480481我想我找到了最简单的方法,因为我对使用自己很感兴趣:)

我尝试了所有选项从这里和从其他一些论坛/页面…Windows不能使用readline.