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

Jul 29, 2016 am 08:45 AM
define

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.


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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explore the importance and role of define function in PHP Explore the importance and role of define function in PHP Mar 19, 2024 pm 12:12 PM

The importance and role of the define function in PHP 1. Basic introduction to the define function In PHP, the define function is a key function used to define constants. Constants will not change their values ​​during the running of the program. Constants defined using the define function can be accessed throughout the script and are global. 2. The syntax of define function The basic syntax of define function is as follows: define("constant name","constant value&qu

defineHow to define multi-line macros defineHow to define multi-line macros Oct 11, 2023 pm 01:24 PM

define defines a multi-line macro by using `\` to divide `do { \ printf("%d\n", x); \ } while (0)` into multiple lines for definition. In a macro definition, the backslash `\` must be the last character of the macro definition and cannot be followed by spaces or comments. When using `\` for line continuation, be careful to keep the code readable and make sure there is a `\` at the end of each line.

defineHow to define conditional compilation defineHow to define conditional compilation Oct 11, 2023 pm 01:20 PM

defineConditional compilation can be achieved using the `#ifdef`, `#ifndef`, `#if`, `#elif`, `#else` and `#endif` preprocessing directives.

define usage of function macro define usage of function macro Oct 11, 2023 pm 12:00 PM

The usage of define function macro: 1. Define a simple calculation macro, "#define SQUARE(x) ((x) * (x))"; 2. Define a macro with multiple parameters, "#define MAX(a , b) ((a) > (b) ? (a) : (b))"; 3. Define macros with complex expressions, "#define ABS(x) ((x) < 0 ? -(x ) : (x))”.

Detailed explanation of define usage Detailed explanation of define usage Oct 11, 2023 am 11:53 AM

define usage: 1. Define constants; 2. Define function macros: 3. Define conditional compilation; 4. Define multi-line macros.

The difference between typedef and define The difference between typedef and define Sep 26, 2023 am 10:41 AM

The difference between typedef and define lies in type checking, scope, readability, error handling, memory usage, etc. Detailed introduction: 1. Type checking, the type alias defined by typedef is a real type, and type checking will be performed, while the macro defined by define is just a simple text replacement, and type checking will not be performed; 2. Scope, the type alias defined by typedef The scope of is local and only valid within the current scope, while the macro defined by define is global and can be used anywhere; 3. Readability, etc.

How to use define to define constants How to use define to define constants Oct 11, 2023 am 11:57 AM

Usage of define constants: 1. Define numeric constants, "#define PI value"; 2. Define string constants, "#define GREETING "string""; 3. Define expression constants, "#define MAX(a, b) ((a) > (b) ? (a) : (b))”.

Discussion on the value and significance of define function in PHP development Discussion on the value and significance of define function in PHP development Mar 20, 2024 am 08:42 AM

In PHP development, we often encounter situations where we need to define constants. In order to better manage constants and ensure their consistency and maintainability throughout the application, PHP provides the define function to define constants. This article will delve into the value and significance of the define function and provide specific code examples to help readers better understand. 1. Basic syntax and usage of define function In PHP, define function is used to define constants. Its basic syntax is as follows: define(name,

See all articles