.user.ini (додаткові конфіг-файли)

Починаючи з версії 5.3.0, PHP має підтримку файлів INI-конфігурації на рівні директорії. Ці файли обробляються тільки через CGI/FastCGI SAPI. Ця функціональність замінює застаріле розширення PECL htscanner. Якщо у вас встановлено Apache, використовуйте файли .htaccess, для досягнення такого ж ефекта.

На додаток до головного файла php.ini, PHP шукає INI-файли в кожній директорії, стартуючи з директорії запрошеного PHP-файла, та продовжує пошук проходячи до поточної кореневої папки (назва якої міститься в змінній $_SERVER['DOCUMENT_ROOT']). У випадку коли PHP-файл знаходиться за межами кореневої папки, сканується лише його директорія.

Стиль конфігурування через файли .user.ini матиме ефект тільки в режимі INI_PERDIR та INI_USER.

Дві нові INI-директиви - user_ini.filename та user_ini.cache_ttl, контролюють використання користувальницьких INI-файлів.

Директива user_ini.filename встановлює назву файла, яку PHP шукає в кожній директорії; якщо встановлено пустий рядок, то PHP не сканує нічого. Початково назва цього файла - .user.ini.

Через директиву user_ini.cache_ttl контролюється частота перечитування INI-файла. Початково встановлено 300 секунд (5 хвилин).

add a note add a note

User Contributed Notes 6 notes

up
27
philsward at gmail dot com
10 years ago
If you have no idea what "PHP_INI_PERDIR" or "PHP_INI_USER" are or how they relate to setting a .user.ini file, take a look at the ini.list page: http://www.php.net/manual/en/ini.list.php

Basically, anything in the "Changeable" column labeled as PHP_INI_SYSTEM can't be set in the .user.ini file (so quit trying).  It can ONLY be set at the main php.ini level.
up
21
Anteaus at thenox dot com
9 years ago
"If you are using Apache, use .htaccess files for the same effect."

To clarify, this applies only to Apache module mode. If you put php directives in .htaccess on an Apache CGI/FastCGI server, this will bomb the server out with a 500 error. Thus, you unfortunately cannot create a config which caters for both types of hosting, at least not in any straightforward way.
up
4
signups at altillc dot com
3 years ago
For those looking for an example... .user.ini should be formatted as a simple list of [KEY]=[VALUE]\n sets.  For example, a one-line .user.ini file that serves solely to change the max allowable upload file size to 5Mb is:

upload_max_filesize="5M"
up
7
Anonymous
4 years ago
Since the .user.ini is read from public directories, it's contents will be served to anyone requesting it and potientially show them sensitive configuration settings.

Add these lines to your .htaccess to block requests to it :
<Files ".user.ini"> 
    Require all denied
</Files>
up
8
interfaSys
13 years ago
This article should be made clearer.
".htaccess-style INI files" meant to me that the ini settings had to follow the syntax used in .htaccess, but this is not the case!

You have to use
register_globals=on
and not
php_flag register_globals on

Also, the changes can take a while to propagate to all processes if you have a long process time out.
Restarting php-fpm can give you an answer quicker :)
up
-17
info at vincentraal.nl
5 years ago
Be aware that PECL htscanner doesn't work (yet) on PHP7.0.

'pecl install htscanner' throws an "zend_hash_update’ undeclared'" error.
To Top