_php tips for installing and using PHP extensions HiDef to improve define performance

Source: Internet
Author: User
Tags apc constant definition fpm
Official website: http://pecl.php.net/package/hidef
Brief introduction:
Allow definition of User defined constants in simple INI files, which are then-like processed internal, constants 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 internal variables, without using define performance issues.

The author says HiDef is initialized in PHP module INIT, before Apache starts spawning children.
Before Apache started, PHP created and initialized these constants when it was started, so there was no need to define constants in PHP, and there was no problem with performance.
Also available under Nginx, the following is the installation process:

1, download and extract 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, 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 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 there is no Hidef.ini_path defined in the php.ini file, the default. ini file read location is/hidef, just create the file Vi/hidef/hidef.ini manually.

# Vi/usr/local/webserver/php/etc/hidef.ini (Adjust the path according to the situation)
Copy 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 String str is contained in double quotes, or the string content is written directly. If you use single quotes, the single quotation marks are also 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 the phpinfo (), where 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 converts a constant to an array and saves it to a user cache. Although the constants exist in memory, each time PHP requests, you still need to read cache, defined separately, so there is no significant performance improvement. I tested the definition of 25 constants, and the function using APC was 0.01ms faster than defining constants directly.

Use 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 the ' APC ' to increase ' performance of scripts/applications, this mechanism was provided to stream Line the process of mass constant definition. However, this function does not perform as.

For a better-performing solution, try the hidef extension from PECL.

HiDef is recommended for use in the APC documentation.

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.