且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何获取PHP 5.3.8读取.user.ini文件?

更新时间:2022-12-05 22:43:43

从其他成员的评论中收集了一些线索,我已经能够进行足够的研究以正确回答问题,以供将来参考.

Gathering some clues from other members' comments, I've been able to do enough research to answer the question properly for future reference.

如PHP文档的常规安装注意事项部分所述,PHP可以通过以下两种方式之一与Apache服务器一起运行:

As explained in the General Installation Considerations section of the PHP documentation, PHP can run alongside an Apache server in one of two ways:

  1. 直接在Apache中作为Apache模块(mod_php)也称为SAPI(服务器应用程序编程接口),或者
  2. 作为通过CGI(通用网关接口)或FastCGI协议与Apache通信的独立可执行文件.

当PHP作为Apache中的模块运行(Mac OS X Server上的默认设置)时,PHP无法直接访问文件系统,而Apache提供了PHP完成其工作所需的一切.这意味着不能选择从文件系统获取最新的,按目录的配置选项.这意味着Apache需要负责将每个目录的设置移交给PHP处理器,因此必须通过.htaccess进行设置(Apache处理并传递给PHP)

When PHP runs as a module within Apache (the default setup on a Mac OS X Server), PHP doesn't have direct access to the filesystem, and Apache supplies everything PHP needs to do its job. Which means picking up last-minute, per-directory configuration options from the filesystem is not an option. This means Apache needs to be responsible for handing any per-directory settings to the PHP processor and therefore must be set via .htaccess (which Apache processes and passes to PHP)

当PHP以其自身的进程运行(通过CGI或FastCGI与Apache通信)时,PHP处理器能够在开始处理脚本之前直接访问目录结构,因此可以在其上加载其他配置文件基于目录的基础,这将影响解析错误的显示(无法在脚本运行时进行决定,因为如果脚本无法解析,PHP将无法遵循其中的任何指令).

When PHP runs as it's own process (communicating with Apache via CGI or FastCGI), the PHP processor is able to access the directory structure directly before it starts to process your script and so it is possible to load an additional configuration file on a per-directory basis which would affect things like the displaying of parse errors (impossible to decide at runtime of a script, because if the script doesn't parse, PHP can't follow any instructions therein).

因此,简短的版本是,如果PHP作为Apache模块运行,则需要通过.htaccess文件设置每个目录的配置指令,或切换到通用网关接口.

So the short version is, if PHP is running as an Apache module, you need to set per-directory configuration directives though an .htaccess file, or switch to Common Gateway Interface.