Php with readline support compiled for windows

Is there a compiled php package with built-in readline support?

readline is required to use php interactively.

I looked how to compile php for Windows, but they require MS Visual Studio, which I do not have.

+6
source share
4 answers

Readline extension is not available on Windows. I think you can compile PHP under cygwin by including the --with-readline option

+4
source
  //The readline library is not available on Windows. <?php if (PHP_OS == 'WINNT') { echo '$ '; $line = stream_get_line(STDIN, 1024, PHP_EOL); } else { $line = readline('$ '); } ?> 

I found this code directly from php documentation. As you can see, there is no readline library support on Windows machines (at least in the ddefault package), which is crap, but you can get something like this by doing the "$ line = blah, blah" that you see in the above code .

I tried and did it using the standard cmd window (although I think that the interactive php mode will not work in windows, no matter what), but this is better than not having user input (if you really remember all this code).

+2
source

It may be a bit late, but here is a solution that solved this problem for me: In the C # Console style, I wrote a small class that can readLine() , as well as writeLine($str) :

 class Console { const READLINE_MAX_LENGTH = 0xFFFF; const WRITELINE_NEWLINE = "\n"; private static /*Resource*/ $stdin; private static /*Resource*/ $stdout; public static function /*void*/ close () { fclose(self::$stdin); fclose(self::$stdout); } public static function /*void*/ open () { self::$stdin = fopen('php://stdin', 'r'); self::$stdout = fopen('php://stdout', 'w'); } public static function /*string*/ readLine () { return stream_get_line(self::$stdin, self::READLINE_MAX_LENGTH, "\r\n"); } public static function /*void*/ writeLine (/*string*/ $str) { fwrite(self::$stdout, $str); fwrite(self::$stdout, self::WRITELINE_NEWLINE); } } 

Usage example:

 Console::open(); echo "Input something: "; $str = Console::readLine(); if (is_string($str)) Console::writeLine($str); else echo "ERROR"; Console::close(); 

EDIT: This method obviously only works if the parent process does not modify STDOUT or STDIN.

+1
source

Given the answer from galymzhan, another option for running PHP interactively on Windows is to use one of the PHP REPLs. You will not get tab completion as it depends on readline.

The REPL that worked for me so far is PHP-Shell

http://jan.kneschke.de/projects/php-shell/

0
source

Source: https://habr.com/ru/post/911451/


All Articles