reading a block of lines in a file using php

后端 未结 5 1500
旧时难觅i
旧时难觅i 2020-12-20 03:16

Considering i have a 100GB txt file containing millions of lines of text. How could i read this text file by block of lines using PHP?

i can\'t use file_get_

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-20 03:58

    The fread approach sounds like a reasonable solution. You can detect whether you've reached the end of a line by checking whether the final character in the string is a newline character ('\n'). If it isn't, then you can either read some more characters and append them to your existing string, or you can trim characters from your string back to the last newline, and then use fseek to adjust your position in the file.

    Side point: Are you aware that reading a 100GB file will take a very long time?

提交回复
热议问题