"Background": Because the file function is a one-time to read all the content into memory, and PHP in order to prevent some poorly written programs to take up too much memory and cause the system memory shortage, so that the server is down, so think of a good way.
"Ideas":
01 idea 1: Use PHP to execute Linux commands, copy one file content (A.log) to another file (B.log) Cat A.log >>b.log02 idea 2: Execute the Linux head command with PHP, get the content, A row of rows is written to another file (B.log). Cat a.log|wc-lsed-n ' 1 P ' a.logfileputcontents (' B.log ', $content, file_append);
"Code Implementation":
1//02. read 1G of File contents 2 Public Function Testgetlarge () 3 {/*{{{*/4 #01. Method 1 Direct Cat Post redirect 5 #if (' usecat ' = = ' Usecat ') 6 if (0 && ' usecat ' = = ' Usecat ') 7 {8 ' cat A.log >>b.log '; 9} #02. With Flie_put_contents, a line reads and appends a line to the if (' usefileputcontents ' = = ' usefileputcontents ') of {/*{{{*/$li Nenum = ' Cat a.log|wc-l '; for ($i =1; $i <= $lineNum; $i + +) * * $content = ' sed-n ' $i p ' a.log '; 18 File appended with file_put_contents (' B.log ', $content, file_append); }/*}}}*/