Official website: http://pecl.php.net/package/hidef
Introduction:
Allow definition of user defined constants in simple ini files, which are then processed like internal constants, without any
of the usual Performance penalties.
Allows the use of simple ini files to define required constants, just like using internal variables, without the performance issues of using Define.
The author said Hidef is initialized in php module init, before apache starts spawning children.
Before apache starts, these constants are created and initialized when PHP starts, so there is no need to define constants in php , there is no problem with performance!
It is also available under Nginx. The following is the installation process:
1. Download and unzip it into the directory
# wget http://pecl.php.net/get/hidef-0.1 .8.tgz
# tar zxvf hidef-0.1.8.tgz
# cd hidef-0.1.8
2. There is no configure file, execute phpize to create the file
# /usr/local/webserver/php/bin/phpize
# ./configure --enable-hidef --with-php-config=/usr/local/webserver/php/bin/php-config
# make
# make install
3. Add to the php.ini file
# vi /usr/local/webserver/php/etc/php.ini
--------------------------------------------------
extension=hidef.so
hidef.ini_path=/usr/local/webserver/php/etc/
----------------------- -------------------------------------------------- -----
Note that if hidef.ini_path is not defined in the php.ini file, the default .ini file reading location is /hidef. You only need to manually create the file vi /hidef/hidef.ini. Can.
# vi /usr/local/webserver/php/etc/hidef.ini (Adjust the path here according to the situation)
Copy code The code is as follows:
[hidef]
int ANSWER = 42;
str HX = "9enjoy";
float PIE = 3.14159;
Here, int is used for integers, float is used for floating point numbers, and str is used for strings.
The value of the string str is enclosed in double quotes, or the string content is written directly. If single quotes are used, the single quotes will also be used as the content of the string.
For example, str HX='9enjoy', what is actually stored is not 9enjoy, but '9enjoy'.
4. Reload php-fpm
# /usr/local/webserver/php/sbin/php-fpm reload
At this time, check phpinfo() As a result, you can see the defined variables at hidef.
----------------------------------------- ---------------------------------------------
Attachment:
If APC is used, apc provides a method to define constants. apc_define_constants and apc_load_constants. apc_define_constants converts constants into arrays and stores them in a user cache. Although the constants are stored in memory, each time PHP requests it, it still needs to read the cache and define them separately, so there will be no obvious performance improvement. I tested defining 25 constants, and using the apc function was 0.01ms faster than defining the constants directly.
Use like this:
if(!apc_load_constants('defined')) {
$constants = array(
'HX' => TRUE,
'D_BUG' => ; 1
);
apc_define_constants('defined', $constants);
}
define() is notoriously slow. Since the main benefit of APC is to increase the performance of scripts /applications, this mechanism is provided to streamline the process of mass constant definition. However, this function does not perform as well as anticipated.
For a better-performing solution, try the hidef extension from PECL.
APC’s documentation recommends using hidef.
http://www.bkjia.com/PHPjc/323515.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323515.htmlTechArticleOfficial website: http://pecl.php.net/package/hidef Introduction: Allow definition of user defined constants in simple ini files, which are then processed like internal constants, without any of...