search
HomeBackend DevelopmentPHP TutorialInstallation and writing of php extension modules

For the installation and writing of PHP extension modules, friends in need can refer to it.


1. PHP source code installation (taking php6 as an example)

Download the source code of php6 from the official website and unzip it

Enter the unzipped folder

./buildconf --force

./configure --prefix=/usr/local/php6 --enable-fpm

The above two lines are used to configure the installation information, ./ indicates using the program in the current directory, --prefix indicates the directory to be installed

make Compile php source code

make install Install

/usr/local/php6/bin -v This can be used to test whether the installation is successful


2.PHP extension module installation

How to load modules (pcntl as an example)

cd Command to enter the ext/pcntl folder under the source code

/usr/local/php6/bin/phpize The phpize program is a program used to load an extension. Here you need to use the phpize of the php that needs to load the extension (if you have multiple phps)

./configure--with-php-config=/usr/local/php6/bin/php-config Configure the information of the extension module. The reason for the following path is the same as above (select the configuration of the PHP that needs to load the extension). This is to make the configuration of PHP and the extension module the same

make Compile

After compilation, pcntl.so will be generated under modules in the current directory

Copy pcntl.so to the PHP installation directory (preferably under ext)

Modify php.ini (you can find this file by running phpinfo() and searching for the php.ini method. It is usually under lib. If the path you find does not have php.ini, you must create a new one yourself)

Add the path extensions=pcntl.so inside

Then it’s ready to run


3.PHP custom extension module

Suppose you need a function called computeDistance(positionX, positionY)

Write the content of distance.skel file as

int computeDistance(int positionX,int positionY) This file explains what modules we need

./ext_skel--extname=distance --proto=distance.skel

The program ext_skel is used above to generate the framework of the entire module The two parameters are Module name, module description file

Enter the newly generated module folder

Modify config.m4

dnl PHP_ARG_WITH(ccvita, for ccvita support,

dnl Make sure that the comment is aligned:

dnl [ --with-distance Include distance support])

Delete the dnl in front of these three lines

Modify distance.c

Find the PHP_FUNCTION function and change the parameters to computeDistance , that is, change it to the name of the function we need to call, and modify the function content by ourselves

The next steps are the same as above

phpize

./configure

make

Copy

Modify configuration file


php


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
How to make PHP applications fasterHow to make PHP applications fasterMay 12, 2025 am 12:12 AM

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

PHP Performance Optimization Checklist: Improve Speed NowPHP Performance Optimization Checklist: Improve Speed NowMay 12, 2025 am 12:07 AM

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

PHP Dependency Injection: Improve Code TestabilityPHP Dependency Injection: Improve Code TestabilityMay 12, 2025 am 12:03 AM

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

PHP Performance Optimization: Database Query OptimizationPHP Performance Optimization: Database Query OptimizationMay 12, 2025 am 12:02 AM

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

Simple Guide: Sending Email with PHP ScriptSimple Guide: Sending Email with PHP ScriptMay 12, 2025 am 12:02 AM

PHPisusedforsendingemailsduetoitsbuilt-inmail()functionandsupportivelibrarieslikePHPMailerandSwiftMailer.1)Usethemail()functionforbasicemails,butithaslimitations.2)EmployPHPMailerforadvancedfeatureslikeHTMLemailsandattachments.3)Improvedeliverability

PHP Performance: Identifying and Fixing BottlenecksPHP Performance: Identifying and Fixing BottlenecksMay 11, 2025 am 12:13 AM

PHP performance bottlenecks can be solved through the following steps: 1) Use Xdebug or Blackfire for performance analysis to find out the problem; 2) Optimize database queries and use caches, such as APCu; 3) Use efficient functions such as array_filter to optimize array operations; 4) Configure OPcache for bytecode cache; 5) Optimize the front-end, such as reducing HTTP requests and optimizing pictures; 6) Continuously monitor and optimize performance. Through these methods, the performance of PHP applications can be significantly improved.

Dependency Injection for PHP: a quick summaryDependency Injection for PHP: a quick summaryMay 11, 2025 am 12:09 AM

DependencyInjection(DI)inPHPisadesignpatternthatmanagesandreducesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itallowspassingdependencieslikedatabaseconnectionstoclassesasparameters,facilitatingeasiertestingandscalability.

Increase PHP Performance: Caching Strategies & TechniquesIncrease PHP Performance: Caching Strategies & TechniquesMay 11, 2025 am 12:08 AM

CachingimprovesPHPperformancebystoringresultsofcomputationsorqueriesforquickretrieval,reducingserverloadandenhancingresponsetimes.Effectivestrategiesinclude:1)Opcodecaching,whichstorescompiledPHPscriptsinmemorytoskipcompilation;2)DatacachingusingMemc

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

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.