


Installation and use of hidef, a PHP extension that improves define performance
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 of user defined constants in simple ini files, which are then processed like internal variables, without any
of the usual performance penalties.
The same, and there are no performance issues with 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 is no problem with performance. Got it!
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-config=/usr/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. Can.
# 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 definition at hidef variable.
-------------------------------------------------- ----------------------------------
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')) {
_constants('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.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio
