Diviner

Class LinesOfALargeFile

Definedsrc/filesystem/linesofalarge/LinesOfALargeFile.php:21
GroupFilesystem
ExtendsLinesOfALarge

Read the lines of a file, one at a time. This allows you to process large files without holding them in memory. In most cases, it is more efficient (and certainly simpler) to read the entire file and explode() it. For more information, see LinesOfALarge. See also LinesOfALargeExecFuture, for a similar abstraction that works on executed commands.

foreach (new LinesOfALargeFile('/some/large/logfile.log') as $line) {
  // ...
}

If the file can not be read, a FilesystemException is thrown.

Tasks

Construction

Internals

Methods

public this __construct($file_name)

parametersstring$file_nameFile path to read.
returnthis

To construct, pass the path to a file.

public void __destruct()

returnvoid

Closes the file handle.

private $this closeHandle()

return$this

Close the file handle, if it is open.

public string readMore()

returnstringNext chunk of the file.

Read the file chunk-by-chunk.

protected void willRewind()

returnvoid

Closes the file handle if it is open, and reopens it.