1

私は2つのサーバーを持っています

両方のサーバーには、128M のデータという同じ php memory_limit があります。

私の開発サーバーはスクリプトを正常に実行しますが、本番サーバーでは致命的なエラーが発生します: 134217728 バイトの許容メモリサイズが使い果たされました (32 バイトを割り当てようとしました) ...

私の質問は、PHP の memory_limits が同じであっても、prod 環境でメモリ不足になる他の理由は何ですか?

4

1 に答える 1

2

序文

PHP は、Apache [HTTPD サーバー] の上で実行されるモジュールです。これには、Web サーバーによって公開されたフックのライブラリに対して php インタープリターをリンクすることが含まれます。

原因

Now it can exhaust due to scripts running allocating memory [RAM] & reach its threshold & get such errors.

Example big loops running & saving lots of data in memory which may over RUN the Memory

あなたができる可能な最適化

memory_limit = 32M to your server's main php.ini file (recommended, if you have access)
php_value memory_limit 32M in your .htaccess file in the 

これらは、メモリが不足しているページの回避策です。

ini_set('memory_limit', '-1'); overrides the default PHP memory limit (On individual php pages wherever you need extra memory)

また、HTTP サーバー (apache.conf または http.conf) で実行できるいくつかの最適化

RLimitCPU,RLimitNPROC, RLimitMEM parameters can be adusted

メモリが不足しているため、RLimitMEMを調整できます

Syntax: RLimitMEM soft-bytes [hard-bytes]
Example: RLimitMEM 1048576 2097152

This directive sets the soft and hard limits for maximum memory usage of a process in bytes. It takes one or two parameters. The first parameter sets the soft resource limit for all processes. The second parameter sets the maximum resource limit. Either parameter can be a number, or ``max'', which indicates to the server that the limit should match the maximum allowed by the operating system configuration. Raising the maximum resource limit requires the server to be running as the user ``root'' or in the initial start-up phase.

.htaccess ファイルにも行を入れることができます [共有ホスティングでは、php.ini および http.conf ファイルにアクセスできなかったためです。

于 2014-10-29T18:03:55.390 に答える