Basically, I'm looking to read lines from STDIN, but I don't want to block while waiting for new data. Almost like using a stream with a timeout.
$stdin = fopen('php://stdin', 'r');
do {
$line = fgets($stdin);
// No input right now
if (empty($line)) {
// Do something before waiting for more input
}
} while (1);
Figured it out, use stream_set_blocking
Docs to disable blocking. Sets $line
to false
when no input is available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With