问题
Storage::disk('local')
->append('/newsletter_lists/'.$contact_file_name.'.csv',
$contact->email.','.$contact->salutation.','.$contact->lastname.','.$contact->unsubscribelink.','.$contact->bonus
);
This is the code in Laravel that is writing to csv file inside a foreach loop (chunk loading from database).
But as far as I know the append() method, is opening the file everytime, loads the content in memory, adds the new line and saves the file again, which with a large number of records (65 000) takes a long time.
I am trying to find a way to append to the end of the file without loading the contents in memory if possible or am I am taking the wrong approach here?
回答1:
I took the @d3L advice and used plain php to append to files and not to use the append() method of laravel, which is loading the content everytime it has to append a line.
$file = fopen(Storage::disk('local')->path('test.csv'), "a+b");
来源:https://stackoverflow.com/questions/54659226/laravel-local-disk-append-taking-up-a-lot-of-memory