Home > Backend Development > PHP Tutorial > define Installation and use of hidef, a PHP extension that improves define performance

define Installation and use of hidef, a PHP extension that improves define performance

WBOY
Release: 2016-07-29 08:45:36
Original
1086 people have browsed it

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.
 Allow definition Simple ini files to define the required constants, just like using internal variables, and 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, and there will be no performance problems. !
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-c/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.
# vi /usr/local/webserver/php/etc/hidef.ini (Adjust the path here according to the situation)

Copy the 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 the results of phpinfo(), and you can see the defined variables at hidef.
 提高define性能的php扩展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')) {
                                                                                                             ('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.
The use of hidef is recommended in the APC documentation.
The above introduces the installation and use of define, the PHP extension hidef that improves the performance of define, including the content of define. I hope it will be helpful to friends who are interested in PHP tutorials.


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template