Linux C language extension _php tutorial for PHP

Source: Internet
Author: User
Tags configuration php
First, build PHP environment
Download PHP 5.2.6 source code and unzip
Compile and install, build PHP environment

Second, create an extension project

Enter the source directory
CD php5.2.6/ext/
./ext_skel--extname=my_ext
Create a project named My_ext that will eventually generate my_ext.so

Third, change the configuration and program
$ VI EXT/MY_EXT/CONFIG.M4

Depending on your own choice, you will

DNL Php_arg_with (My_ext, for my_ext support,
DNL Make sure, the comment is aligned:

DNL [--with-my_ext Include my_ext support])
Modified into

Php_arg_with (My_ext, for my_ext support,
Make sure, the comment is aligned:

[--with-my_ext Include My_ext support])
or the

DNL php_arg_enable (My_ext, whether to ENABLE My_ext support,
DNL Make sure, the comment is aligned:

DNL [--enable-my_ext enable my_ext support])
Modified into

Php_arg_enable (My_ext, whether to ENABLE My_ext support,

Make sure, the comment is aligned:
[--enable-my_ext enable my_ext support])

$ VI ext/my_ext/php_my_ext.h

Will
Php_function (confirm_my_ext_compiled); /* For testing, remove later. */
Change to
Php_function (Say_hello);


$ VI ext/my_ext/my_ext.c

Will
Zend_function_entry php5cpp_functions[] = {
Php_fe (confirm_my_ext_compiled, NULL)/* For testing, remove later. */
{null, NULL, NULL}/* must is the last line in php5cpp_functions[] */
};
Change to
Zend_function_entry php5cpp_functions[] = {
Php_fe (Say_hello, NULL)
{null, NULL, NULL}/* must is the last line in php5cpp_functions[] */
};

Added at the end:
Php_function (Say_hello)
{
zend_printf ("Hello world\n");
}

Four, compiling
$ CD My_ext
$/usr/local/php/bin/phpize
PS: If it appears: Cannot find autoconf .... Error message, you will need to install autoconf (the installation process is slightly)
$./configure--with-php-config=/usr/local/php/bin/php-config
$ make

This will compile the my_ext/modules/my_ext.so

Five, configuration php.ini
Put the my_ext.so into /usr/local/php/ext/Directory

$ VI php.ini

The modifications are added as follows:
Extension_dir = '/usr/local/php/ext/'
extension=my_ext.so

Six, Test
$ VI test.php
Say_hello ();
?>

$/usr/local/php/bin/php test.php
Hello world.

It's done.

PS: If you have any questions please leave a message, we discuss together

http://www.bkjia.com/PHPjc/319688.html www.bkjia.com true http://www.bkjia.com/PHPjc/319688.html techarticle First, build PHP environment download PHP 5.2.6 source code and unzip the installation, build PHP environment Two, create extension project into the source directory CD php5.2.6/ext/./ext_skel--extname=my_ext Create name ...

  • 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.