首页 > 代码库 > php.ini设置相关信息汇总

php.ini设置相关信息汇总

  1. display_errors
    本条指令控制PHP是否输出errors、notices、warnings。一般在开发模式下打开,在产品模式下关闭。
    有点坑的是,php.ini中,文件开头就又关于display_errors指令的介绍,但是,在后面才是设置。我第一次就是在开头处设置了,但是在文件后面因为还存在display_errors真正设置的地方,导致后面的设置覆盖了前面的设置,从而使我的设置一直无法生效。坑!坑!坑!
    在爬坑过程中用到的几个方法:
    1. ini_get()
    2. php --ini    查看php加载的是哪个php.ini文件
    3. php-fpm -t    通过php-fpm 测试配置文件指令查看php-fpm加载的php-fpm.conf文件路径
    4. phpinfo()

    另外的一个总结:php.ini的加载逻辑
    ; PHP attempts to find and load this configuration from a number of locations.
    ; The following is a summary of its search order:
    ; 1. SAPI module specific location.
    ; 2. The PHPRC environment variable. (As of PHP 5.2.0)
    ; 3. A number of predefined registry keys on Windows (As of PHP 5.2.0)
    ; 4. Current working directory (except CLI)
    ; 5. The web server‘s directory (for SAPI modules), or directory of PHP
    ; (otherwise in Windows)
    ; 6. The directory from the --with-config-file-path compile time option, or the
    ; Windows directory (C:\windows or C:\winnt)
    由上可知,php会
    1. 首先从sapi的参数中查看是否指定了php.ini
    2. 如果没有就通过PHPRC环境变量指定的路径查找
    3. 如果没有,或者PHPRC环境变量未设置,则从registry keys注册表从找(专用于windows)
    4. 从当前的工作目录中查找(除了CLI)
    5. 从web服务器的目录中查找(对于SAPI模块),或者PHP的目录中
    6. 从php编译时指定的--with-config-file-path中查找,或者在windows directory(C:\windows or C:\winnt)
  2. output_buffering
    ; Output buffering is a mechanism for controlling how much output data
    ; (excluding headers and cookies) PHP should keep internally before pushing that
    ; data to the client. If your application‘s output exceeds this setting, PHP
    ; will send that data in chunks of roughly the size you specify.
    ; Turning on this setting and managing its maximum buffer size can yield some
    ; interesting side-effects depending on your application and web server.
    ; You may be able to send headers and cookies after you‘ve already sent output
    ; through print or echo. You also may see performance benefits if your server is
    ; emitting less packets due to buffered output versus PHP streaming the output
    ; as it gets it. On production servers, 4096 bytes is a good setting for performance
    ; reasons.
    ; Note: Output buffering can also be controlled via Output Buffering Control functions.
    由上可知,本条指令控制是否打开输出缓存。
    注意,当打开输出缓存时,header()、session_start()等于response header有关的函数,可能可以在输出之后调用。当关闭本指令时,因为响应头是向发出的,所以在这些函数之前,不能存在输出。
  3. ?

 

php.ini设置相关信息汇总