Extension INI Entries
Defining
php.ini
directives (i.e., INI entries) in an
extension is easy. Most of the work involves setting up the global
struct explained earlier in Section 14.10.3. Each entry in the INI
structure is a global variable in the extension and thus has an entry
in the global struct and is accessed using
FOO_G(my_ini_setting)
. For the most part you can
simply comment out the indicated sections in the skeleton created by
ext_skel
to get a working INI directive, but we
will walk through it here anyway.
To add a custom INI entry to your extension, define it in your main
foo.c
file using:
PHP_INI_BEGIN( ) STD_PHP_INI_ENTRY("foo.my_ini_setting", "0", PHP_INI_ALL, OnUpdateInt, setting, zend_foo_globals, foo_globals) PHP_INI_END( )
The arguments to the STD_PHP_INI_ENTRY( )
macro are: entry name, default entry value, change permissions,
pointer to change modification handler, corresponding global
variable, global struct type, and global struct. The entry name and
default entry value should be self-explanatory. The change
permissions parameter specifies where this directive can be changed.
The valid options are:
-
PHP_INI_SYSTEM
The directive can be changed in
php.ini
or inhttpd.conf
using the php_admin_flag/php_admin_value directives.-
PHP_INI_PERDIR
The directive can be changed in
httpd.conf
or.htaccess
(ifAllowOverride
OPTIONS
is set) using the php_flag/php_value directives.-
PHP_INI_USER
The user can change the directive using the
ini_set( )
function in scripts. ...
Get Programming PHP now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.