Developing PHP extensions with C (Basic version) _php Tutorial

Source: Internet
Author: User
The first step: Build an extended skeleton.
[HTML]
cd/usr/local/src/php-5.3.6/ext/
./ext_skel--extname=laiwenhui

cd/usr/local/src/php-5.3.6/ext/
./ext_skel--extname=laiwenhui Step Two: Modify the compilation parameters.
[HTML] View PLAINCOPYPRINT?CD Php-5.3.6/ext/laiwenhui
VI CONFIG.M4

CD Php-5.3.6/ext/laiwenhui
VI config.m4 Remove
Php_arg_enable (Laiwenhui, whether to ENABLE Laiwenhui support,
[--enable-laiwenhui enable Laiwenhui support])
DNL in front of two lines
Modified to:
DNL Otherwise Use enable:
Php_arg_enable (Laiwenhui, whether to ENABLE Laiwenhui support,
DNL Make sure, the comment is aligned:
[--enable-laiwenhui enable Laiwenhui support])


Step Three: Write code
[HTML]
Vim php_laiwenhui.h

Vim php_laiwenhui.h
In

Php_function (confirm_laiwenhui_compiled);

Add a row later

Php_function (test);

[HTML]
Vim LAIWENHUI.C

Vim LAIWENHUI.C

In

Php_fe (confirm_laiwenhui_compiled, NULL)

Added later
Php_fe (test, NULL)


* * Add the following code to the last side of the file: *
[HTML]
Php_function (Test)
{
Char *arg = "This is my first extention!";
int Len;
Char *STRG;

Len = spprintf (&STRG, 0, "%s\n", Arg);
Return_stringl (STRG, Len, 0);
}

Php_function (Test)
{
Char *arg = "This is my first extention!";
int Len;
Char *STRG;

Len = spprintf (&STRG, 0, "%s\n", Arg);
Return_stringl (STRG, Len, 0);
Step Fourth: Compile the Code
[HTML]
/usr/local/php/bin/phpize
./configure--with-php-config=/usr/local/php/bin/php-config
Make
Make install

/usr/local/php/bin/phpize
./configure--with-php-config=/usr/local/php/bin/php-config
Make
Make install
My PHP installation path is:/usr/local/php
This time a file is generated/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/laiwenhui.so

To edit the PHP configuration file php.ini, add the extension:
[HTML]
Vim php.ini

Vim PHP.ini added under [PHP] module:
[HTML]
Extension = laiwenhui.so

Extension = laiwenhui.so Modify the Extension_dir in the php.ini file to this directory:
[HTML]
Extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"

Extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"


Fifth Step: Check the installation results

1. Restart Php-fpm,ngixn
2./use/local/php/bin/php-m
See if there is a laiwenhui extension included.


Sixth step: Execute the test code


Create test.php at the site root directory
Vim test.php
Code content is as follows
echo Test ();

The results after execution are:
This is my first extention!

If you can successfully complete the above steps, congratulations on completing the first extension.

http://www.bkjia.com/PHPjc/477166.html www.bkjia.com true http://www.bkjia.com/PHPjc/477166.html techarticle The first step: Build an extended skeleton. [HTML] cd/usr/local/src/php-5.3.6/ext/./ext_skel--extname=laiwenhui cd/usr/local/src/php-5.3.6/ext/./ext_skel-- Extname=laiwenhui Second step: Repair ...

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