class DeviceIdGenerator
{
const CHUCK_SIZE = 4096;
private $path;
public function __construct(string $path)
{
$this->path = $path;
}
public function read()
{
$buffer = '';
$handle = fopen($this->path, 'r+');
try {
do {
$next = fread($handle, self::CHUCK_SIZE);
if ($next === '') {
break;
}
$next = $buffer . $next;
$parts = preg_split("/(\r|\n|\r\n|,)/", $next);
$buffer = array_pop($parts);
foreach ($parts as $part) {
$part && yield $part;
}
} while (true);
} finally {
fclose($handle);
}
}
}