Nginx 或 PHP FPM 忽略 php.ini 中的 memory_limit

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15962634/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 10:16:24  来源:igfitidea点击:

Nginx or PHP FPM ignores memory_limit in php.ini

nginxphp

提问by user2272788

Server info: Ubuntu Server, Nginx, PHP FPM

服务器信息:Ubuntu 服务器、Nginx、PHP FPM

in /etc/php5/fpm/php.iniI have: memory_limit = 512Min /etc/php5/fpm/php-fpm.confI have: php_admin_value[memory_limit] = 512M

/etc/php5/fpm/php.ini我有:memory_limit = 512M/etc/php5/fpm/php-fpm.conf我有:php_admin_value[memory_limit] = 512M

php_value[memory_limit] = 512M

My phpinfo looks like:

我的 phpinfo 看起来像:

PHP Version 5.3.10-1ubuntu3.6

PHP 版本 5.3.10-1ubuntu3.6

System Build Date

系统构建日期

Linux snserver 3.2.0-40-generic #64-Ubuntu SMP Mon Mar 25 21:22:10 UTC 2013 x86_64 Mar 11 2013 14:34:24

Linux snserver 3.2.0-40-generic #64-Ubuntu SMP Mon Mar 25 21:22:10 UTC 2013 x86_64 Mar 11 2013 14:34:24

Server API

服务器接口

FPM/FastCGI

FPM/FastCGI

Virtual Directory Support

虚拟目录支持

disabled

残疾

Configuration File (php.ini) Path

配置文件(php.ini)路径

/etc/php5/fpm 

Loaded Configuration File

加载的配置文件

/etc/php5/fpm/php.ini

/etc/php5/fpm/php.ini

Scan this dir for additional .ini files /etc/php5/fpm/conf.d

扫描此目录以获取其他 .ini 文件 /etc/php5/fpm/conf.d

Additional .inifiles parsed

.ini解析的其他文件

/etc/php5/fpm/conf.d/curl.ini, /etc/php5/fpm/conf.d/gd.ini, /etc/php5/fpm/conf.d/mcrypt.ini, /etc/php5/fpm/conf.d/memcache.ini, /etc/php5/fpm/conf.d/mysql.ini, /etc/php5/fpm/conf.d/mysqli.ini, /etc/php5/fpm/conf.d/pdo.ini, /etc/php5/fpm/conf.d/pdo_mysql.ini...

/etc/php5/fpm/conf.d/curl.ini, /etc/php5/fpm/conf.d/gd.ini, /etc/php5/fpm/conf.d/mcrypt.ini, /etc/php5/fpm/conf.d/memcache.ini, /etc/php5/fpm/conf.d/mysql.ini, /etc/php5/fpm/conf.d/mysqli.ini, /etc/php5/fpm/conf.d/pdo.ini, /etc/php5/fpm/conf.d/pdo_mysql.ini...

This server is protected with the Suhosin Patch 0.9.10 Copyright (c) 2006-2007 Hardened-PHP Project Copyright (c) 2007-2009 SektionEins GmbH

此服务器受 Suhosin Patch 0.9.10 保护 版权所有 (c) 2006-2007 Hardened-PHP 项目 版权所有 (c) 2007-2009 SektionEins GmbH

This program makes use of the Zend Scripting Language Engine: Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies with Xdebug v2.2.2, Copyright (c) 2002-2013, by Derick Rethans

该程序使用 Zend 脚本语言引擎:Zend Engine v2.3.0,版权所有 (c) 1998-2012 Zend Technologies with Xdebug v2.2.2,版权所有 (c) 2002-2013,Derick Rethans

...

...

memory_limit

内存限制

128M

128M

upload_max_filesize

上传最大文件大小

20M

20M

in /etc/nginx/nginx.conf:

在 /etc/nginx/nginx.conf 中:

    user www-data;

worker_processes 2;

pid /var/run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {
    client_max_body_size 20M;

    ##

    # Basic Settings

    ##
    fastcgi_buffers 16 16k;

    fastcgi_buffer_size 32k;

    proxy_buffers 4 512k;

    proxy_buffer_size 256k;

    proxy_busy_buffers_size 512k;

    fastcgi_read_timeout 3600;

    sendfile on;

    tcp_nopush on;

    tcp_nodelay on;

    keepalive_timeout 300;

    keepalive_requests 50;

    #ssl_ciphers HIGH:!aNULL:!MD5:!kEDH;

        #ssl_prefer_server_ciphers on;

        #ssl_protocols TLSv1;

        #ssl_session_cache shared:SSL:10m;

        #ssl_session_timeout 10m;

    types_hash_max_size 2048;

    # server_tokens off;

    # server_names_hash_bucket_size 64;

    # server_name_in_redirect off;

    include /etc/nginx/mime.types;

    default_type application/octet-stream;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;

    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # nginx-naxsi config
    ##
    # Uncomment it if you installed nginx-naxsi
    ##

    #include /etc/nginx/naxsi_core.rules;

    ##
    # nginx-passenger config
    ##
    # Uncomment it if you installed nginx-passenger
    ##

    #passenger_root /usr;
    #passenger_ruby /usr/bin/ruby;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}


The problem is when i change upload_max_filesizesize then the phpinfowill show the new value, but when I change memory_limitthen nothing changes. I guess in somewhere the memory_limit is overwrited. But i cannot find it. Can anyone help me?

问题是当我更改 upload_max_filesize大小时,phpinfo将显示新值,但是当我更改时,memory_limit没有任何变化。我猜在某个地方 memory_limit 被覆盖了。但我找不到它。谁能帮我?

采纳答案by troseman

You can take Nginx out of the picture, it just passes the request on, it's in php-fpm running your php code.

你可以把 Nginx 去掉,它只是传递请求,它在 php-fpm 中运行你的 php 代码。

you might check your suhosin settings, suhosin.memory_limit.

你可以检查你的 suhosin 设置,suhosin.memory_limit。

when you see your phpinfo output there should be 2 columns, master and local for memory_limit, what do these each show?

当你看到你的 phpinfo 输出时,应该有 2 列,master 和 local 用于 memory_limit,它们分别显示什么?

128M is the default for memory_limit in php 5.3

128M 是 php 5.3 中 memory_limit 的默认值

回答by temple

In /etc/php5/fpm/php-fpm.confI have php_admin_value[memory_limit] = 512M

/etc/php5/fpm/php-fpm.conf我有php_admin_value[memory_limit] = 512M

This works for me.

这对我有用。

回答by pilot

The problem may be in fpmthe process duplication, even you change your /etc/php5/fpm/php.ini it was not effect.

问题可能出在fpm的进程重复上,即使你改了你的/etc/php5/fpm/php.ini也没有效果。

  • Stop php5-fpm with (ubuntu): sudo service php5-fpm stop
  • check that no more fpm processes: sudo ps ax | grep fpm
  • if any kill it all with: sudo kill -9 pid
  • be sure that you kill all fpm processes
  • restart: sudo service php5-fpm restart
  • 使用 (ubuntu) 停止 php5-fpm: sudo service php5-fpm stop
  • 检查没有更多的 fpm 进程:sudo ps ax | grep fpm
  • 如果有的话用: sudo kill -9 pid
  • 确保您杀死所有 fpm 进程
  • 重启:sudo service php5-fpm 重启

回答by Edu Wass

Just FYI,

仅供参考,

you should also check in /etc/php5/fpm/pool.dfor any files.

您还应该检查/etc/php5/fpm/pool.d中的任何文件。

It just happened to me that no matter what I wrote on /etc/php5/fpm/php-fpm.conf it would get overrided by /etc/php5/fpm/pool.d/www.conf !

我碰巧无论我在 /etc/php5/fpm/php-fpm.conf 上写了什么,它都会被 /etc/php5/fpm/pool.d/www.conf 覆盖!

So if none of the above answers are not working for you, you should check this (I just lost half hour to this).

因此,如果以上答案都不适合您,您应该检查一下(我刚刚为此浪费了半个小时)。

回答by fedmich

Also encountered this now and wanted to increase memory of our server in a DigitalOcean droplet

现在也遇到了这个问题,想在 DigitalOcean droplet 中增加我们服务器的内存

To summarize, here is what I did

总而言之,这就是我所做的

sudo nano /etc/php5/fpm/php-fpm.conf

-- press Ctrl-W to do a search in nano text editor
-- if php_admin_value[memory_limit] is there, change it
php_admin_value[memory_limit] = 512M

sudo service php5-fpm restart

You don't need to restart nginx, just restarting phpwould be enough.

您不需要重新启动 nginx,只需重新启动php就足够了。

回答by Anthony Vipond

For me it also ignored php.ini and I had to do the following:

对我来说,它也忽略了 php.ini,我必须执行以下操作:

vim /etc/php-fpm.d/www.conf

php_admin_value[memory_limit] = 10000M ;128M

Then restart php-fpm:

然后重启php-fpm:

service php-fpm restart

回答by Jim Moo

Ok this is daft but I had memory_limit set to 2GB, which isn't understood. When I changed that to 2000M it worked!

好吧,这很愚蠢,但我将 memory_limit 设置为 2GB,这是不明白的。当我将其更改为 2000M 时,它起作用了!