[PHP-SRC] The structure of a PHP extension

Source: Internet
Author: User

The content is php5.6.14 for example.

To have a php extension shelf, use the prepared/ext/ext_skel tool in the source code to generate a running extension skeleton.

Run without an option./ext_skel, you can view Help text for all available options.

1) ./ext_skel--extname=myext(extension), automatically generates an extension directory myext, and a step-by prompt appears:

  

It means using your own extension to go through these 8 steps, first look at the next step.

2) VI config.m4 mainly open the following two options, remove the previous DNL, let the extension support--with-myext,--enable-myext option, one to introduce the extension, one to open the extension:

The rest of the M4 syntax, and so on to look back, currently only two items.

  

3) compile and install extensions

CD myextphpize   /usr/local/php/bin/phpize). /configure--with-php-config=/usr/local/php/bin/php-Configmake
Make test (can be ignored) make install

  

4) Use

After installing the generated myext.so extension file in this directory,/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226

Finally, add myext.so to php.ini,extension = myext.so

Use php-m to see if the installation was successful and the browser to view it with Phpinfo.

5) Development

After the extension has been compiled into PHP, after modifying the extension source file, only need to re-make && sudo make install.

Q&a

When installing multiple versions of PHP locally, add PHP command-line aliases in ~/.bash_profile, such as:

' Alias php5.6.14=/usr/local/php5.6.14/bin/php '

The source ~/.bash_profile takes effect immediately and allows you to view the results of the operation using Php5.6.14-f 1.php under the CLI.

PHP Life cycle:

(Command execution) expansion request initialization--(Request script) Extension Request init--(Execute script) extension requests shutdown--(Completion request) expansion module shutdown

These are in your extension master file myext.c.

Php_minit_function (Myext) {
# Register constants or classes such as initialization operations return SUCCESS;} Php_rinit_function (Myext) {
# For example record request start time return SUCCESS;} Php_rshutdown_function (Myext) {
# For example, record request end time, log return SUCCESS;} Php_mshutdown_function (Myext) {
# Unregister some persistent resources return SUCCESS;}

Link:http://www.cnblogs.com/farwish/p/5208653.html

@ Black eyed poet <www.farwish.com>

[PHP-SRC] The structure of a PHP extension

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.