PHP extension-generation and compilation of extensions and php extension generation and compilation

Source: Internet
Author: User
Tags sapi

PHP extension-generation and compilation of extensions and php extension generation and compilation

First of all, PHP extensions can be compiled in two ways:
Method 1: Compile the extension directly when compiling PHP
Method 2: The extension is compiled into a. so file, and the loading path is configured in php. ini;

The following describes how to create and compile PHP extensions:
Download the PHP source code, decompress it, and start the operation under the root directory of the source code,
1. Use ext_skel to generate the extension framework, as shown below:

➜ php-5.6.24 cd ~/Downloads/tmp/php-5.6.24➜ php-5.6.24 cd ext➜ ext ./ext_skel --extname=myfirstext

 

After executing ext_skel, the developer will be prompted for subsequent operation steps. This operation step is one of the two extended compilation methods, as shown below:

To use your new extension, you will have to execute the following steps:1.  $ cd ..2.  $ vi ext/plogger/config.m43.  $ ./buildconf4.  $ ./configure --[with|enable]-plogger5.  $ make6.  $ ./sapi/cli/php -f ext/plogger/plogger.php7.  $ vi ext/plogger/plogger.c8.  $ make

2. Modify the ext/myfirstext/config. m4 file.
Focus on the line10-18 code, which is used to enable this extension when setting./configure, delete the dnl of line16 and line18, and understand dnl as a annotator.

14 dnl Otherwise use enable:1516 dnl PHP_ARG_ENABLE(myfirstext, whether to enable myfirstext support,17 dnl Make sure that the comment is aligned:18 dnl [ --enable-myfirstext Enable myfirstext support])1920 if test "$PHP_MYFIRSTEXT" != "no"; then21 dnl Write more examples of tests here...

The above two steps are public. The following describes the two methods for compiling PHP extensions,
Method 1: Compile the extension directly when compiling PHP
3. Execute./buildconf in the source code root directory, as shown below:
4. Run./configure-enable-myfirstext in the source code root directory.
To reduce Compilation Time, you can specify not to compile certain modules in the configure phase, for example:

./configure --without-iconv --enable-debug --enable-myfirstext --disable-cgi --enable-cli --without-pear --disable-xml --without-mysql

5. Execute make in the source code root directory.
Note that after the compilation is successful, do not execute make install, because at this point, the extension myfirstext has been compiled successfully and the corresponding php binary file has been generated, which is in./sapi/cli/php

Method 2: The extension is compiled into a. so file, and the loading path is configured in php. ini.
3. Run the phpize command under the extension directory ext/myfirstext /.
4. Run the./configure-enable-myfirstext command under the extension directory ext/myfirstext /.
5. Run make in the extension directory ext/myfirstext /.
After you execute make, the corresponding. so file is generated under ext/myfirstext/modules, and configured in php. ini to load the file.

Verify whether the extension is loaded successfully
Run./sapi/cli/php-f ext/myfirstext. php
You can also use php-m to list all extensions and check whether myfirstext exists. Run the command:./sapi/cli/php-m | grep myfirstext.
The above verification indicates that the extended compilation is successful. However, no c-related code has been edited so far, and everything is generated by ext_skel by default. What functions does this extension myfirstext contain? As follows:

➜ php-5.6.24 ./sapi/cli/php -r 'print_r(get_extension_funcs("myfirstext"));'

OK. So far, I am familiar with the generation, configuration, and compilation of the PHP extension framework. Next, we need to add a function to the extended myfirstext.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.