PHP allows the use of extended, direct use of the C language to develop PHP functionality, due to the problem of compilation, many of the underlying and framework of the basic work if PHP will inevitably bring additional overhead, reduce the system throughput, it is inevitable that yaf is the idea, the framework encapsulated in the extension, Minimizes system overhead and approximates the level of performance without frames.
The first is to get PHP source code, here to provide a PHP source, the latest is PHP7.1, not enough to take into account I have been using the environment, here choose PHP 5.4.31 as an example.
The second is the PHP compilation deployment under the Windows platform. Visual Studio 2008 needs to be used in Windows studio,php 5.4.31, and it needs to be upgraded to vS2008 SP1 compilation for normal compilation. Otherwise, there will be an issue that cannot be loaded after deployment.
Note that before this, Windows needs to install PHP first, and add PHP to the environment variables, it is recommended to install XAMPP, one step.
VS2008 SP1:
PHP 5.4.31 Source code:
PHP5ts.lib:
After you install the development environment, you are ready to begin configuration. Developing extensions under Windows is a lot more hassle when creating projects than on Ubuntu, one that requires PHP's source code, and one that requires building a project first, then manually configuring it, and not just executing a script like Ubuntu. Deploy the source code under the E:\PROJECTS\PHP-5.4.45-SRC path, and then run the terminal (Cmd.exe) using the administrator and then
CD E:\Projects\php-5.4. ---extname=hello
You can build a PHP extension development project (path in E:\Projects\php-5.4.45-src\ext\hello) to see the project file as shown
Use the previously installed VS2008SP1 to open the project. You can see something like this
Right-click the item to open the right-click menu--Properties, as follows
Click C/c++--> General, find and open as shown in the red circle
This is an address is modified to the absolute address of the PHP source deployment, so that there will not be a slight move on the project location can not compile the problem, the modified address is as follows
After the configuration, you also need to do some PHP source settings,
(1) Copy the E:\Projects\php-5.4.45-src\win32\build\config.w32.h.in to the E:\Projects\php-5.4.45-src\main, and remove the last. in suffix, or it will appear when you compile
Not found. Main\config.w32.h File Errors
(2) You need to download Php5ts.lib and configure it separately, or it will appear
1>link:fatal error LNK1181: Unable to open input file "Php5ts.lib"
Error, unzip php5ts.lib to E:\Projects\php-5.4.45-src\build, then open the project Properties---> Linker---> Input and change the value to look like the logo.
So far, you can start compiling the project. The compiled dynamic library can be seen through the phpinfo () function by adding extensions after php.ini and then restarting Xampp.
The third is the Ubuntu platform under the compiler deployment, in Ubuntu under the development of PHP extension is much simpler, first install XAMPP for Ubuntu, installation method can refer to my previous article "Ubuntu16.04 PHP Development environment configuration." Then configure the system's PHP environment, execute the following command
Link PHP and XAMPP in your system so that you can easily test your PHP extension. The system's PHP command path is cd/usr/local/bin, so switch to that path first
cd/usr/local/binsudo MVPHP php-5.4. $sudo MVphp-cgi php-cgi-5.4. $sudo MVPhp-config php-config-5.4. $sudo MVPhpize phpize-5.4. $sudo LN-s/opt/lampp/bin/php-5.4. toPHPsudo LN-s/opt/lampp/bin/php-cgi-5.4. tophp-CGIsudo LN-s/opt/lampp/bin/php-config-5.4. tophp-Configsudo LN-s/opt/lampp/bin/phpize-5.4. toPhpize
sudo ln-s/opt/lampp/etc/php.ini/usr/local/lib/php.ini
After execution, PHP used by XAMPP Apache is the same as PHP used by the terminal.
Next you can start to create the project, set the PHP source code placed in the HOME/PROJECTS/PHP-5.4.45-SRC
Note that Ext_skel does not have execute permission at first, it needs to execute the following command to give Execute permission
chmod 777 Ext_skel
Then you can create a project to execute the following commands
cd/home/projects/php-5.4. -src/extsudo ./ext_skel--extname=Hello
CD Hello
Gedit CONFIG.M4/* Find lines 16th and 18th to remove the previous DNL comment, as shown in */sudo phpizesudo ./Configure sudo Make Make Install sudo make Test
Note After you save the file, you also need to execute phpize, or you will encounter issues that do not generate the. so file.
PHP Extension Development Build Environment