search
HomeBackend DevelopmentPHP Tutorialdefine Installation and use of hidef, a PHP extension that improves define performance

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
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
define怎么定义多行宏define怎么定义多行宏Oct 11, 2023 pm 01:24 PM

define定义多行宏可以通过使用 `\` 将 `do { \ printf("%d\n", x); \ } while (0)` 分成了多行进行定义。在宏定义中,反斜杠 `\` 必须是宏定义的最后一个字符,且不能有空格或注释跟随。使用 `\` 进行续行时,注意保持代码的可读性,并确保每个行末都有 `\`。

探究PHP中define函数的重要性与作用探究PHP中define函数的重要性与作用Mar 19, 2024 pm 12:12 PM

PHP中define函数的重要性与作用1.define函数的基本介绍在PHP中,define函数是用来定义常量的关键函数,常量在程序运行过程中不会改变其值。利用define函数定义的常量,在整个脚本中均可被访问,具有全局性。2.define函数的语法define函数的基本语法如下:define("常量名称","常量值&qu

define怎么定义条件编译define怎么定义条件编译Oct 11, 2023 pm 01:20 PM

define定义条件编译可以使用 `#ifdef`、`#ifndef`、`#if`、`#elif`、`#else` 和 `#endif` 预处理指令来实现。

define定义函数宏的用法define定义函数宏的用法Oct 11, 2023 pm 12:00 PM

define定义函数宏的用法:1、定义简单的计算宏,“#define SQUARE(x) ((x) * (x))”;2、定义带有多个参数的宏,“#define MAX(a, b) ((a) > (b) ? (a) : (b))”;3、定义带有复杂表达式的宏,“#define ABS(x) ((x) < 0 ? -(x) : (x))”。

typedef和define区别typedef和define区别Sep 26, 2023 am 10:41 AM

typedef和define区别在类型检查、作用范围、可读性、错误处理和内存占用等。详细介绍:1、类型检查,typedef定义的类型别名是真正的类型,会进行类型检查,而define定义的宏只是简单的文本替换,不会进行类型检查;2、作用范围,typedef定义的类型别名的作用范围是局部的,只在当前的作用域内有效,而define定义的宏是全局的,可以在任何地方使用;3、可读性等等。

define用法详解define用法详解Oct 11, 2023 am 11:53 AM

define用法:1、定义常量;2、定义函数宏:3、定义条件编译;4、定义多行宏。

define定义常量的用法define定义常量的用法Oct 11, 2023 am 11:57 AM

define定义常量的用法:1、定义数值常量,“#define PI 数值”;2、定义字符串常量,“#define GREETING "字符串"”;3、定义表达式常量,“#define MAX(a, b) ((a) > (b) ? (a) : (b))”。

PHP开发中define函数的价值和意义探讨PHP开发中define函数的价值和意义探讨Mar 20, 2024 am 08:42 AM

在PHP开发中,我们经常会遇到需要定义常量的情况。为了更好地管理常量并确保其在整个应用程序中的一致性和可维护性,PHP中提供了define函数来定义常量。本文将深入探讨define函数的价值和意义,并提供具体的代码示例来帮助读者更好地理解。1.define函数的基本语法和用法在PHP中,define函数用于定义常量,其基本语法如下:define(name,

See all articles

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 agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment