The installation and use of PHP extension hidef to improve define performance

Source: Internet
Author: User
Tags apc constant definition
Brief introduction:
Allow definition of user defined constants in simple INI files, which is then processed like internal constants, without Any
Of the usual performance penalties.
Allows you to use a simple INI file to define the constants you need, just as you would with an internal variable, without using define performance issues.

The author says HiDef is initialized in PHP module INIT, before Apache starts spawning children.
Before Apache started, PHP started to create and initialize these constants, so that you do not need to define constants in PHP, performance naturally no problem!
Also available under Nginx, the following is the installation process:

1. Download and unzip into the catalogue

# wget Http://pecl.php.net/get/hidef-0.1.8.tgz
# tar ZXVF hidef-0.1.8.tgz
# CD hidef-0.1.8

2. No configure file, execute phpize 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 inside

# 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 read location is/hidef, and you can simply create the file Vi/hidef/hidef.ini manually.

# Vi/usr/local/webserver/php/etc/hidef.ini (here to adjust the path according to the situation)
Copy the code code as follows:
[HiDef]
int ANSWER = 42;
str HX = "9enjoy";
float PIE = 3.14159;

here integers with int, floating-point numbers with float, string with Str.
The value of the string str is enclosed in double quotation marks, or the string content is written directly. If single quotation marks are used, the single quotation marks will also be the contents of the string.
such as str hx= ' 9enjoy ', the actual storage is not 9enjoy, is ' 9enjoy '.

4, Reload PHP-FPM can

#/USR/LOCAL/WEBSERVER/PHP/SBIN/PHP-FPM Reload

At this point, look at the results of phpinfo () and you can see the defined variables at HiDef.


-----------------------------------------------------------------------------

Report:

If you use APC,APC, you provide a way to define constants. Apc_define_constants and Apc_load_constants. Apc_define_constants the constant to an array into a user cache. Although there is a constant in memory, but each time the PHP request, still need to read the cache, defined separately, so there is no significant performance improvement. I tested the definition of 25 constants, and using APC's functions is 0.01ms faster than defining constants directly.

This is used:
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 was provided to stream Line 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.
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.