Home >Backend Development >PHP Tutorial >Installation 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
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 |