0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【PHP】Allowed memory size of *** bytes exhausted エラーの対応

Posted at

エラー内容

PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes) in ファイルパス on line 〇〇
処理に必要なメモリサイズが、PHPのメモリ使用上限設定(memory_limit)を超えてます!!!

対策1 そもそもメモリを使いすぎない実装にする

コードを見直しましょう。

  • 非効率なロジックになっていないk

対策2 メモリ上限を上げる

  • まず、現在のPHPのメモリ上限を確認します
php -i | grep memory_limit

memory_limit => 512M => 512M のように表示されます。

  • php.ini ファイルを編集して、 メモリ上限を変更します。(vim以外でも可)
    • ファイルの場所はphp -i | grep php.iniで探します
vim /opt/homebrew/etc/php/7.3/php.ini

memory_limit の設定を検索し、適切な値に変更します。
※vimだと/memory を入力すると対象箇所が検索できます。

memory_limit = 1024M など、に適宜書き換えます。

変更後、もう一度メモリ上限が適用されているか確認します。

php -i | grep memory_limit

必要に応じて、PHPを再起動します。

brew services restart php
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?