4

ini_set memory_limit在safe_mode下不可用

 2 years ago
source link: https://www.laruence.com/2010/04/13/1408.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

ini_set memory_limit在safe_mode下不可用

如果你ini_set("memory_limit", *)返回了false,
不妨检查下, 是否开启了安全模式(手册中没有述及)..
一句话, 记录下.
在安全模式下不能使用ini_set的指令:

  1. 1. max_execution_time
  2. 2. memory_limit
  3. 3. child_terminate

11 Comments

  1. minesweeper
    minesweeper August 9, 2021

    Thanks for sharing this valuable content. In my view, if all webmasters and bloggers were creating content as good as you do, the website would be more useful than ever.

  2. smalla
    smalla November 7, 2012

    太对了!竟然还有人非要说这个不能设置,原来还真的是安全模式下

  3. feng
    feng October 24, 2011

    坑爹啊,找了半天原因。。。多谢!

  4. laruence
    laruence April 29, 2011

    @luckgo 呵呵,那看看是不是因为php.max_input_time导致的

  5. luckgo
    luckgo April 28, 2011

    看了,禁用函数里没这个函数,服务器的php.ini完全拿到本机上来运行都是正常的。
    主要问题在这里,是上传文件时碰到问题,我随便写个脚本调试时是正常的,比如我ini_set后,马上ini_get,能够看到我ini_set的值,说明没有问题,但如果是上传文件脚本,就有问题了,很奇怪。传一个10M多文件,也不是很大,但只要超过php.ini中的max_execution_time时间就有问题,我设置的ini_set就无效,这算哪门子事,真是邪乎?
    报错提示的是脚本代码开始的行(不含注释)运行超时,而代码开始的行(不含注释)无论是什么如简单赋值语句都会这样。 我所说的代码开始的行是指<?php后,不含注释的第一行。
    在本机中,超时时间是我ini_set设置的时间,报错超时的行是真正上传脚本所在的行,没有任何问题。
    实在搞不明白,我的php.ini配置没任何问题,
    post_max_size = 100M
    upload_max_filesize = 100M
    上传文件上限已经设的够大了。
    我google一下,有人解释是某些操作系统需打开display_startup_errors,但我开启了这个项也不行。
    我感觉是操作系统问题。

  6. laruence
    laruence April 24, 2011

    @luckgo 有没有可能是因为服务器把ini_set列入了禁用函数列表呢? 你可以把ini_set的结果打出来看看.

  7. luckgo
    luckgo April 24, 2011

    忘了说了,服务器运行环境是windows 2008 r2 + php 5.3.5 (vc9) + apache 2.2.17,
    把服务器的php.ini拿到本机运行,一切正常,本机运行环境是windows vista + php 5.3.5 (vc9) + apache 2.2.17
    就操作系统部一样,其他配置都一样,为什么本机正常,而服务器不正常呢?

  8. luckgo
    luckgo April 24, 2011

    Laruence帮帮忙,一个很奇怪问题!
    php.ini配置:
    safe_mode = Off
    display_errors = Off
    error_reporting = E_ALL & ~E_DEPRECATED
    max_execution_time = 300
    在PHP上传程序脚本中,开头加入
    error_reporting(E_ALL);
    ini_set(‘display_errors’, ‘On’);
    ini_set(‘max_execution_time’, 30);
    执行PHP程序,明显超过300秒,但却没有任何错误提示,说明ini_set没有生效,奇怪!
    然后,改php.ini,设置
    display_errors = On
    再次执行PHP脚本,最后提示超过300秒的错误,为什么不是30秒,奇怪啊!ini_set居然没有生效!
    这是怎么回事呢?

  9. […] ini_set(‘memory_limit’,’64M’); //重置php可以使用的内存大小为64M,一般在远程主机上是不能修改php.ini文件的,只能通过程序设置。注:在safe_mode(安全模式)下,ini_set失效 […]

  10. CFC4N
    CFC4N April 15, 2010

    哈,原来是这样啊…
    前段时间,我编写 sql injection,xss,csrf 事例,都跟服务器环境有关,需要频繁更改服务器的环境,想用ini_set,结果,不管我怎么弄,也不生效…纳闷到现在,后来搜了N多遍,也没解决,也不知道什么原因
    今天在您这里看到了,恍然大悟,哈…万分感谢

  11. 好黑啊
    好黑啊 April 13, 2010

    顶了慢慢看

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Comment

Name*

Email*

Website

Save my name, email, and website in this browser for the next time I comment.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK