Generation and compilation of PHP extensions

Source: Internet
Author: User
Tags php source code sapi
First, there are two ways to compile PHP extensions:
Method One: Compile the extension directly when compiling PHP
Mode two: The extension is compiled into a. So file, the load path is configured in php.ini;

The steps to create and compile a php extension are described below:
Download PHP source code, and unzip, in the root directory of the source code to start operations,
1. Use Ext_skel to generate the extension framework as follows:

➜PHP-5.6.24 CD ~/downloads/tmp/php-5.6.24➜php-5.6.24 CD ext
➜ext./ext_skel--extname=myfirstext

Ext_skel after the execution, will prompt the developer to follow the steps, this operation step is to expand the two ways of compiling the way one step, as follows:

To use your new extension, you'll have to execute the following steps: $ CD. $ vi ext/plogger/config.m4 $./buildconf $./configure--[with|enable]-plogger $ make $./sapi/cli/php-f Ext/plogger/plog Ger.php $ VI ext/plogger/plogger.c $ make

2. Modify the file Ext/myfirstext/config.m4
Focus on the LINE10-18 code, used to set the./configure when the command option for this extension is enabled, and the dnl of Line16 and Line18 is deleted, and DNL is interpreted as an annotation.

DNL Otherwise use enable:16 dnl php_arg_enable (Myfirstext, whether to enable Myfirstext support,dnl do sure that the COM ment is ALIGNED:DNL [--enable-myfirstext enable myfirstext support]) if test "$PHP _myfirstext"! = "no"; THENDNL Write More examples of tests ...

The above two steps are public, the following will explain the two ways to compile PHP extensions,
Method one: Compile PHP directly to compile the extension in
3. Execute the./buildconf under the source root directory, as follows
4. Execute under the source code root directory./configure–enable-myfirstext
To reduce compilation time, it is possible to indicate in the Configure phase that some modules are not compiled, such as:

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

5. Execute make under the source root directory
Note that after the compilation is successful, do not install, because the extension myfirstext has been compiled successfully, and the corresponding PHP binaries have been generated, it is in./sapi/cli/php

Mode two: The extension is compiled into a. So file, and the load path is configured in php.ini
3. Execute the phpize command under the extended directory ext/myfirstext/
4. Execute the./configure–enable-myfirstext command under the extended directory ext/myfirstext/
5. Execute make under the extended directory ext/myfirstext/
After you execute make, the corresponding. So file is generated under Ext/myfirstext/modules and is configured in the php.ini to load the file.

Verify that the extension is loaded successfully
Execution./sapi/cli/php-f ext/myfirstext/myfirstext.php
or list all extensions through php-m to see if there are myfirstext, execute the command:./sapi/cli/php-m | grep myfirstext
The above verification indicates that the extension was compiled successfully. But so far, has not edited the C related code, everything is Ext_skel by default generated, see this extension myfirstext contains what functions? As follows:

➜php-5.6.24./sapi/cli/php-r ' Print_r (Get_extension_funcs ("Myfirstext")); '

OK, so far familiar with the build, configuration, and compilation of the PHP extension framework. Next, add your own function to the extension myfirstext.

  • Related Article

    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.