Sheng
Sheng

Reputation: 25

Using PHP,how to insert a line efficient to the end of a very large .txt file

the .txt file is about 500M,when i use fopen,my computer just can not work,so i wanna any other way to finish the task

Upvotes: 0

Views: 120

Answers (2)

hsz
hsz

Reputation: 152294

If you are running PHP script on Linux, you can do it with:

$newLine  = 'some text';
$filename = 'large.txt';
system('echo "' . $newLine . '" >> ' . $filename);

Upvotes: 0

Esailija
Esailija

Reputation: 140236

Try

 $fp = fopen( "file.txt", 'a' );
 fwrite( $fp, "\n" );
 fclose( $fp );

Upvotes: 1

Related Questions