How to read giant text file in PHP? [duplicate]
问题 This question already has answers here : Reading very large files in PHP (8 answers) Closed 5 years ago . I have few text files with size more than 30MB . How can i read such giant text files from PHP? 回答1: Unless you need to work with all the data at the same moment, you can read them in pieces. Example for binary files: <?php $handle = fopen("/foo/bar/somefile", "rb"); $contents = ''; while (!feof($handle)) { $block = fread($handle, 8192); do_something_with_block($block); } fclose($handle);