nginx 上的 php 内存无法在任何棘手的情况下增加
仅供参考,这个问题是重复的,很多人都问,但我已经收集了我的问题的所有答案,我仍然对问题做了什么或不起作用,但我解释了更多细节,我想知道为什么。 类似
- 致命错误:允许的内存大小已耗尽 268435456 字节(尝试分配 71 字节) 和其他人有很多反应告诉它的重复和任何东西。
情况是 我有 3 个服务器(引擎),运行应用程序(laravel web)。
A. 我的引擎(工作/没有错误):( apache Ubuntu 18.04.6 LTS )
❯ free -m
total used free shared buff/cache available
Mem: 7976 865 497 18 6613 6797
Swap: 0 0 0
B. 我的引擎(不工作/错误分配内存):( nginx )( Ubuntu 18.04.4 LTS )
➜ ~ free -m
total used free shared buff/cache available
Mem: 7975 658 4312 22 3005 7006
Swap: 4095 1 4094
C我的引擎(不工作/错误分配内存):(nginx)(Ubuntu 20.04.1 LTS)
~ » free -m ~
total used free shared buff/cache available
Mem: 1987 1096 112 131 778 568
Swap: 0 0 0
我所做的是运行一个导出 Excel 文件的查询,其中数据是从应用程序构建到现在的,因此需要大量内存、时间或处理。如果昨天看到有 9000 个数据/行。
我所做的(使用我的三台服务器)
- 增加有关 nginx/apache 上内存的配置
- 尝试覆盖 .httaccess/file.php/index.php 上的设置以增加内存处理
- 调整 mysql oracle/mysql mariadb
我的服务器 ( B) 不起作用在这里: (我的配置)
➜ ~ locate php.ini
/etc/php/7.4/apache2/php.ini
/etc/php/7.4/cli/php.ini
/etc/php/7.4/fpm/php.ini
/usr/lib/php/7.4/php.ini-development
/usr/lib/php/7.4/php.ini-production
/usr/lib/php/7.4/php.ini-production.cli
/usr/lib/php/8.1/php.ini-development
/usr/lib/php/8.1/php.ini-production
/usr/lib/php/8.1/php.ini-production.cli
➜ ~ php -i | grep php.ini
Configuration File (php.ini) Path => /etc/php/7.4/cli
Loaded Configuration File => /etc/php/7.4/cli/php.ini
然后我修改了 php 内存
// [ 1 ]
// /etc/php/7.4/cli/php.ini
max_execution_time = 3600
max_input_time = -1
memory_limit=512M // i have tried set to 2048M or -1 or 99999999999M
,然后重新启动 php 和 nginx 进行测量...
➜ ~ sudo service nginx restart && sudo service php7.4-fpm restart
➜ ~ nginx -s reload
没有错误,但仍然存在问题分配内存卡在 16384 字节 所以我尝试覆盖 laravel/index.php 和 laravel/public/index.php 上 index.php
的设置 我将这些代码粘贴到 .php 文件中。
<?php
set_time_limit(0);
ini_set('memory_limit', '-1');
ini_set('max_execution_time', 360);
仍然存在问题。 我正在调试的是,当我尝试将内存设置为仅 512M 时,它的警报会引导我增加更多内存(允许的内存大小已耗尽 268435456 字节(尝试分配 20480 字节)),但是当我尝试增加到 2048M 时,警报是不同(允许的内存大小为 268435456 字节耗尽(尝试分配 16384 字节),
所以我们可以在这里关闭理解 首先
- 请尝试分配更多 20480 字节 第二个
- 请尝试分配更多 16384 字节。
谁能解释一下为什么?卡在 16384 字节......我增加到最大值。
但在我的第一个使用 apache 的服务器上,它的配置工作和棘手的覆盖而不是 index.php apache 是使用 .htaccess 。
fyi this question is duplicate and many people ask to but i have collect all answer into my question what i did still on problem or doesnt work but i explain more detail and i want to know why.
similar on
- Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 71 bytes)
and other have much response tell its duplicate and anything.
the case is
i have 3 server ( engine ) where run an application ( laravel web ).
A. my engine ( work/no error ): ( apache Ubuntu 18.04.6 LTS )
❯ free -m
total used free shared buff/cache available
Mem: 7976 865 497 18 6613 6797
Swap: 0 0 0
B. my engine ( doesnt work/error allocate memory ): ( nginx ) ( Ubuntu 18.04.4 LTS )
➜ ~ free -m
total used free shared buff/cache available
Mem: 7975 658 4312 22 3005 7006
Swap: 4095 1 4094
C. my engine ( doesnt work/error allocate memory ): ( nginx ) ( Ubuntu 20.04.1 LTS )
~ » free -m ~
total used free shared buff/cache available
Mem: 1987 1096 112 131 778 568
Swap: 0 0 0
what i do is run a query thats export a excel file where the data is from application is build until now , so need a big memory, time or processing. if see on yesterday there is have 9000 data/row.
what i was do ( with my three server )
- increase configuration about memory on nginx/apache
- tried override the setting on .httaccess/file.php/index.php to increase the memory processing
- tunning mysql oracle/mysql mariadb
my server (B) on doesnt work is here :
(my configuration)
➜ ~ locate php.ini
/etc/php/7.4/apache2/php.ini
/etc/php/7.4/cli/php.ini
/etc/php/7.4/fpm/php.ini
/usr/lib/php/7.4/php.ini-development
/usr/lib/php/7.4/php.ini-production
/usr/lib/php/7.4/php.ini-production.cli
/usr/lib/php/8.1/php.ini-development
/usr/lib/php/8.1/php.ini-production
/usr/lib/php/8.1/php.ini-production.cli
➜ ~ php -i | grep php.ini
Configuration File (php.ini) Path => /etc/php/7.4/cli
Loaded Configuration File => /etc/php/7.4/cli/php.ini
then i modified the php memory
// [ 1 ]
// /etc/php/7.4/cli/php.ini
max_execution_time = 3600
max_input_time = -1
memory_limit=512M // i have tried set to 2048M or -1 or 99999999999M
then i restart the php and nginx for measure ...
➜ ~ sudo service nginx restart && sudo service php7.4-fpm restart
➜ ~ nginx -s reload
nothing error but still on problem allocate memory stuck on 16384 bytes
so i tried override the setting on index.php
its on laravel/index.php and laravel/public/index.php
i put these code and paste into .php file.
<?php
set_time_limit(0);
ini_set('memory_limit', '-1');
ini_set('max_execution_time', 360);
still on problem .
what i was debug is when i tried to set the memory only 512M its alert is guide me to increase more memory ( Allowed memory size of 268435456 bytes exhausted (tried to allocate 20480 bytes) ) but when i tried increase into 2048M the alerts is a different ( Allowed memory size of 268435456 bytes exhausted (tried to allocate 16384 bytes)
so we can close understand here
for first
- please try allocate more 20480 bytes
for second - please try allocate more 16384 bytes.
can anyone explain why ? stuck on 16384 bytes ... what ever i increase to the maximum.
but on my first server with apache its work on configuration and tricky of override instead of index.php apache is use .htaccess.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您按照我的理解编辑了
/etc/php/7.4/cli/php.ini
。这只是 php cli 的配置文件。Nginx 正在使用
/etc/php/7.4/fpm/php.ini
您需要在那里更改内存限制
You edited
/etc/php/7.4/cli/php.ini
as I did understand it. This is only the config file for your php cli.Nginx is using
/etc/php/7.4/fpm/php.ini
You need to alter your memory limit there