select()->run(function(Reactor $reactor) { // Set the STDIN stream to "non-blocking" mode stream_set_blocking(STDIN, false); // Echo back the line each time there is readable data on STDIN $reactor->onReadable(STDIN, function() { if ($line = fgets(STDIN)) { echo "INPUT> ", $line, "\n"; } }); // Countdown RUN_TIME seconds then end the event loop $secondsRemaining = RUN_TIME; $reactor->repeat(function() use (&$secondsRemaining) { if (--$secondsRemaining > 0) { echo "$secondsRemaining seconds to shutdown\n"; } else { $reactor->stop(); } }, $msInterval = 1000); });