How to Read a Large Text File Using PHP
How to read a large text file using php
This article will explain the php function gzread. It uses the zlib module to allow your code to read or write compressed files transparently. This allows your files to be delivered to end-users much quicker.
A compressed version of the file is created, and the contents are read into a buffer, which is then decompressed. The buffer is then written to the gzipped file. The zlib function gzread provides a much faster and more efficient method for reading compressed data.
The gzread() function reads from the file referenced by the gz-file pointer, which must have been opened in a read mode (see gzopen()). It shall uncompress at most len(uncompressed) bytes into buf. On success, it shall return the number of bytes decompressed into buf. Otherwise, it shall return 0 or an underlying read error value, which applications may examine using gzerror().
This is a very handy little function that will unzip a.gz file for you, if needed. It has some nice error handling built in, so if you set the wrong output path, for example, an error will be thrown. It's also very fast. To use it, simply pass it the full path to your zipped file (including the '.gz') and it will unzip it for you. The output path is stored in a variable named output_filename, and the number of bytes that need to be read at one time is fixed in a variable called buffer_size.