1
0

More than 1 year has passed since last update.

【Laravel】Storage::disk('local')->append() で out of memoryする

Posted at

Storage::disk('local')->append() で out of memory

正確には何度も繰り返しappend()していたらout of memoryとなりました。
原因は少し前のissueになりますが、githubにありました
Storage::disk('local')->append method run out of memory #24439
issueによるとライブラリの関係でappendを呼ぶ度に、ファイルの中身をメモリに読み込んでいるのが原因のようです。

対応

これはローカルファイルに書き込む場合に起きるのでLaravel使わずにやります。

example.php
$handle = fopen(storage_path("app/hoge.csv"), "a"); // aで追記モード
fwrite($handle, ",");
fclose($handle);

むちゃくちゃ簡単な対応ではあるのですが、メモリが足りない理由がどこかはっきりわからないのでしばらく困ってしまいました。
書き込むデータが大きいのが原因のようにも見えてしまうのですが、フレームワーク側の問題でした。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0