_canReadline = extension_loaded('readline') && $handle === 'php://stdin' ? true : false; $this->_input = fopen($handle, 'r'); } /** * Read a value from the stream * * @return mixed The value of the stream */ public function read() { if ($this->_canReadline) { $line = readline(''); if (!empty($line)) { readline_add_history($line); } return $line; } return fgets($this->_input); } /** * Checks if data is available on the stream * * @param int $timeout An optional time to wait for data * @return bool True for data available, false otherwise */ public function dataAvailable($timeout = 0) { $readFds = array($this->_input); $readyFds = stream_select($readFds, $writeFds, $errorFds, $timeout); return ($readyFds > 0); } }