on-internet
← Community

Non-blocking on STDIN in PHP CLI

Stack Overflow ·

Is there anyway to read from STDIN with PHP that is non blocking: I tried this: stream_set_blocking(STDIN, false); echo fread(STDIN, 1); and this: $stdin = fopen('php://stdin', 'r'); stream_set_blocking($stdin, false); echo 'Press enter to force run command...' . PHP_EOL; echo fread($stdin, 1); but it still blocks until fread gets some data. I noticed a few open bug reports about this (7 years old), so if it can't be done, does any one know any crude hacks that could accomplish this (on Windows and Linux)? https://bugs.php.net/bug.php?id=34972 https://bugs.php.net/bug.php?id=47893 https://bugs

Comments

Sign in or sign up to comment and upvote.

No comments yet.