如何在PHP中正确使用`.user.ini`文件? [英] How to correctly use `.user.ini`-file in PHP?

查看:499
本文介绍了如何在PHP中正确使用`.user.ini`文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的工作目录中,我有两个文件:index.php.user.ini:

In my working directory I have two files: index.php and .user.ini:

.user.ini:

display_errors=on

; http://be2.php.net/manual/en/filter.configuration.php#ini.filter.default
;filter.default = "full_special_chars"

index.php:

<?php
//ini_set("display_errors", "on");

// Use `.user.ini` file:
// http://php.net/manual/en/configuration.file.per-user.php
echo "Setting for 'user_ini.filename': " . ini_get("user_ini.filename");
echo "\n\n";


// It takes up to five minutes, until `.user.ini` is re-read:
echo "Setting for 'user_ini.cache_ttl': " . ini_get("user_ini.cache_ttl");
echo "\n\n";

// http://php.net/manual/en/function.ini-get.php
echo "Setting for 'display_errors': " . ini_get("display_errors");
echo "\n\n";
echo "Setting for 'filter.default': " . ini_get("filter.default");
echo "\n\n";

// php -S localhost:8000
// http://localhost:8000/

使用上面的.user.ini文件(在我的工作目录中),我希望"Setting for 'display_errors': "的值为on1,但它为空.

Using the above .user.ini-file (in my working directory) I expect the "Setting for 'display_errors': " having a value of on or 1, but it's empty.

如何使用.user.ini文件正确更改设置?

How to correctly change settings using the .user.ini-file?

运行php --ini会导致

Configuration File (php.ini) Path: /etc/php5/cli
Loaded Configuration File:         /etc/php5/cli/php.ini
Scan for additional .ini files in: /etc/php5/cli/conf.d
Additional .ini files parsed:      /etc/php5/cli/conf.d/05-opcache.ini,
/etc/php5/cli/conf.d/10-pdo.ini,
/etc/php5/cli/conf.d/20-json.ini,
/etc/php5/cli/conf.d/20-readline.ini

其中不包含我的.user.ini文件.

显式添加.user.ini文件有效:

php --php-ini .user.ini index.php

但是我希望从给定文件夹中运行脚本时会自动读取它.

but I'd like it to be automatically read when running the script from a given folder.

推荐答案

这些文件仅由CGI/FastCGI SAPI处理

These files are processed only by the CGI/FastCGI SAPI

如果您使用的是Apache,请使用.htaccess文件以达到相同的效果.

If you are using Apache, use .htaccess files for the same effect.

因此,如果您将PHP作为Apache模块,从命令行或使用内置服务器运行,则不会处理.user.ini-文件.

So if you run PHP as an Apache module, from the commandline, or using the builtin-Server, the .user.ini-files are not processed.

要查找服务器API,只需生成一个包含以下内容的PHP脚本,然后在您的Web浏览器中调用它即可:

To find out your Server API, simply generate a PHP script with the following content and call it in your webbrowser:

<? phpinfo();

这篇关于如何在PHP中正确使用`.user.ini`文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆