private function getResponse($fh,$timeout = 5,$index = 0)
	{
		$read = array($fh);
		$write  = NULL;
		$except = NULL;
		$num_changed_streams = stream_select($read, $write, $except, 0);

		if ($num_changed_streams > 0) {
			$errorResponse = fread($fh, 6);
			$reason = '';
			if ($errorResponse) {
				// response is binary, we have to unpack it into an array
				$response = unpack('Ccommand/Cstatus_code/Nidentifier',$errorResponse);
				$code = array_key_exists('status_code', $response) ? $response['status_code'] : 255;
				$reason = array_key_exists($code, self::$ERRORS) ? self::$ERRORS[$code] : "Code $code";
			}
			return $reason;
		}
		
		// 10th time through, we give up
		if ($index >= ($timeout * 10)) return '';
		
		usleep(100000);
		return $this->getResponse($fh,$timeout,$index+1);
	}
private function getResponse($fh,$timeout = 5,$index = 0)
	{
		$read = array($fh);
		$write  = NULL;
		$except = NULL;
		$num_changed_streams = stream_select($read, $write, $except, 0);

		if ($num_changed_streams > 0) {
			$errorResponse = fread($fh, 6);
			$reason = '';
			if ($errorResponse) {
				// response is binary, we have to unpack it into an array
				$response = unpack('Ccommand/Cstatus_code/Nidentifier',$errorResponse);
				$code = array_key_exists('status_code', $response) ? $response['status_code'] : 255;
				$reason = array_key_exists($code, self::$ERRORS) ? self::$ERRORS[$code] : "Code $code";
			}
			return $reason;
		}
		
		// 10th time through, we give up
		if ($index >= ($timeout * 10)) return '';
		
		usleep(100000);
		return $this->getResponse($fh,$timeout,$index+1);
	}
private function getResponse ( $ fh , $ timeout = 5 , $ index = 0 ) { $ read = array ( $ fh ) ; $ write = NULL ; $ except = NULL ; $ num_changed_streams = stream_select ( $ read , $ write , $ except , 0 ) ; if ( $ num_changed_streams > 0 ) { $ errorResponse = fread ( $ fh , 6 ) ; $ reason = '' ; if ( $ errorResponse ) { // response is binary, we have to unpack it into an array $ response = unpack ( 'Ccommand/Cstatus_code/Nidentifier' , $ errorResponse ) ; $ code = array_key_exists ( 'status_code' , $ response ) ? $ response [ 'status_code' ] : 255 ; $ reason = array_key_exists ( $ code , self :: $ ERRORS ) ? self :: $ ERRORS [ $ code ] : "Code $code" ; } return $ reason ; } // 10th time through, we give up if ( $ index >= ( $ timeout * 10 ) ) return '' ; usleep ( 100000 ) ; return $ this -> getResponse ( $ fh , $ timeout , $ index + 1 ) ; }
Recursive function to check if there is anything in the stream to read.
Will wait for up to

@param int $fh file handle
@param number $timeout (in seconds) default = 5
@param number $index (used internally as recursion counter - do not provide a value)
@return string empty string for success, or a text message for failure
Recursive function to check if there is anything in the stream to read . Will wait for up to