public function readAndWrite($blocking, $close = false)
{
$this->write($blocking, $close);
$read = [];
$fh = $this->fileHandles;
foreach ($fh as $type => $fileHandle) {
if (0 !== fseek($fileHandle, $this->readBytes[$type])) {
continue;
}
$data = '';
$dataread = null;
while (!feof($fileHandle)) {
if (false !== ($dataread = fread($fileHandle, self::CHUNK_SIZE))) {
$data .= $dataread;
}
}
if (0 < ($length = strlen($data))) {
$this->readBytes[$type] += $length;
$read[$type] = $data;
}
if (false === $dataread || true === $close && feof($fileHandle) && '' === $data) {
fclose($this->fileHandles[$type]);
unset($this->fileHandles[$type]);
}
}
return $read;
}