I am a stranger here.

Jan 20 2012

下回り(asm, c, c++)を経験しているエンジニアはメモリ割当量は自分で管理するものと考えているはずですが、Lightweight Language専門のアプリケーションエンジニアはメモリ割当量をあまり気にしないようです…。

PHPメモリ制限の設定

PHPは、php.ini内のmemory_limitで設定された値までメモリを使用することが出来ます。例えば以下の設定であれば、実行中のPHPプロセスで2MBまでメモリを使用することが出来ます。

memory_limit=2M

PHP実行中にmemory_limitへ達してしまった場合、FATALエラーを出力して処理を停止します。PHPがapache moduleとして実行されている場合、以下の理由でmemory_limitの上限値を大きくしたくありません。

  • FATALエラーは例外ではないためトラップ出来ない(クライアントへレスポンス出来ない)
  • Apacheはブラウザからのアクセスを非同期で受け付ける(Apache側でクライアント接続タイミングを制御できない)
  • クライアント接続数は最大でMaxClientsの設定値まで増加する
  • クライアント1接続当たりApacheが1プロセス動作する(Linux版PHPではthreadが使えないのでforkする)

これが何を意味しているかというと、php.iniが正しく設定されない場合、Apacheの実行プロセスが使用するメモリ量が、サーバに搭載された物理メモリ量を超えてしまうことがあります。

45 notes

  1. kwy8791 reblogged this from oshiire
  2. uchiger reblogged this from ak47
  3. testin reblogged this from ak47
  4. damnlocks reblogged this from osamuya
  5. thun2 reblogged this from darylfranz
  6. anekos reblogged this from bo-rude
  7. akuwano reblogged this from oshiire
  8. yamakozawa reblogged this from atm09td
  9. ds9-garak reblogged this from darylfranz
  10. seinon reblogged this from darylfranz
  11. ilferabeau reblogged this from darylfranz
  12. gijibamboo reblogged this from tiga
  13. atm09td reblogged this from seapomeranian
  14. naok reblogged this from ak47
  15. seapomeranian reblogged this from bo-rude
  16. yu-nyan reblogged this from oshiire
  17. saitamanaka reblogged this from darylfranz
  18. eivy reblogged this from ak47
  19. oshiire reblogged this from ak47
  20. osamuya reblogged this from ak47
  21. komatak reblogged this from takashi0215
  22. knnr reblogged this from layer13
  23. bo-rude reblogged this from tiga
  24. daikantou reblogged this from layer13
  25. layer13 reblogged this from darylfranz
  26. takashi0215 reblogged this from ak47
  27. ase-hujiko reblogged this from darylfranz
  28. darylfranz reblogged this from firebum
  29. firebum reblogged this from ak47
  30. wizardblue reblogged this from ak47
  31. ak47 reblogged this from tiga
  32. tiga posted this
Page 1 of 1