reading a block of lines in a file using php -



reading a block of lines in a file using php -

considering have 100gb txt file containing millions of lines of text. how read text file block of lines using php?

i can't utilize file_get_contents(); because file large. fgets() read text line line takes longer time finish reading whole file.

if i'll using fread($fp,5030) wherein '5030' length value has read. there case won't read whole line(such stop @ middle of line) because has reached max length?

i can't utilize file_get_contents(); because file large. fgets() read text line line takes longer time finish reading whole file.

don't see, why shouldn't able utilize fgets()

$blocksize = 50; // in "number of lines" while (!feof($fh)) { $lines = array(); $count = 0; while (!feof($fh) && (++$count <= $blocksize)) { $lines[] = fgets($fh); } dosomethingwithlines($lines); }

reading 100gb take time anyway.

php file fgets fread

Comments

Popular posts from this blog

c# - Move local mssql database to webhosted MYSQL -

java - How to pass parameters between Request-Scoped Controllers? -

string - what is the difference between "some" == "some\0" and strcmp("some","some\0") in c++? -